不言不语

您现在的位置是: 首页 >  Linux

Linux

nginx 虚拟主机多网站配置

2022-05-31Linux
Nginx 是一个轻量级高性能的 Web 服务器,并发处理能力强,对资源消耗小,无论是静态服务器还是小网站, Nginx 表现更加出色,作为 Apache 的补充和替代使用率越来越高。本文主要是针对虚拟主机的设置,多网站配置方法

Nginx 是一个轻量级高性能的 Web 服务器,并发处理能力强,对资源消耗小,无论是静态服务器还是小网站, Nginx 表现更加出色,作为 Apache 的补充和替代使用率越来越高。本文主要是针对虚拟主机的设置,多网站配置方法


一、这里假设大家的 Nginx 服务器已经安装好,进入 /usr/local/nginx/conf/vhost 目录, 创建虚拟主机配置文件  {域名}.conf( 如test.52linmin.wang.conf )

server {

  listen 80;    # 默认80端口
  server_name test.52linmin.wang;     # 虚拟主机域名
  access_log off;    # 这里是关闭日志,大家根据自己需要修改
  index index.html index.htm index.php;
  include /usr/local/nginx/conf/rewrite/none.conf;
  root /data/wwwroot/test.52linmin.wang;  #    虚拟主机代码目录
  
  #error_page 404 = /404.html;
  #error_page 502 = /502.html;
  
  location ~ [^/]\.php(/|$) {
    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
  }
  
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
    expires 30d;
    access_log off;
  }
  
  location ~ .*\.(js|css)?$ {
    expires 7d;
    access_log off;
  }
  
  location ~ /\.ht {
    deny all;
  }
}


二、打开 Nginx 配置文件 /usr/local/nginx/conf/nginx.conf, 在 http 范围引入虚拟主机配置文件如下:

include vhost/*.conf;


三、重启 Nginx 服务

service nginx restart




文章评论