nginx配置多网站多配置文件控制-------nginx虚拟主机配置

1、修改主配置文件(删除server部分,修改http部分,添加网站配置文件路径,下面我贴出所有配置文件代码)

 #user  nobody;
 worker_processes  1;
  
 #error_log  logs/error.log;
 #error_log  logs/error.log  notice;
 #error_log  logs/error.log  info;
  
 #pid        logs/nginx.pid;
  
  
 events {
     worker_connections  1024;
 }
  
  
  
     #}
  
  
 http {
        include       /usr/local/nginx/conf/mime.types;
        default_type  application/octet-stream;
  
       log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
  
            access_log  /usr/local/nginx/logs/access.log  main;
  
            sendfile        on;
            #tcp_nopush     on;
     #
         keepalive_timeout  65;
     #
     #        #gzip  on;
     #
         include /usr/local/nginx/conf.d/*.conf;
      } 

文件重点主要在加黑那一行

2、创建配置文件目录和网站目录

[root@2df7fb5c5f50 a.ildd.cc]# mkdir /usr/local/nginx/conf.d
[root@2df7fb5c5f50 a.ildd.cc]# mkdir /usr/local/nginx/html/a.ildd.cc/

3、创建网站配置文件

[root@2df7fb5c5f50 a.ildd.cc]# vim /usr/local/nginx/conf.d/a.ildd.cc.conf 

注:配置文件命名要和网站域名一致

server {
     listen       80;
     server_name   a.ildd.cc;
  
     #charset koi8-r;
     #access_log  /usr/local/nginx/logs/host.access.log  main;
     root   /usr/local/nginx/html/a.ildd.cc/;
     if (!-e $request_filename){
             rewrite ^/(.*) /index.php last;  
     }  
  
     location / {
         index  index.php index.html index.htm;
     }
  
     #error_page  404              /404.html;
  
     # redirect server error pages to the static page /50x.html
     #
     error_page   500 502 503 504  /50x.html;
     location = /50x.html {
         root   /usr/local/nginx/html/a.ildd.cc/;
     }
  
     # proxy the PHP scripts to Apache listening on 127.0.0.1:80
     #
     #location ~ \.php$ {
     #    proxy_pass   http://127.0.0.1;
     #}
  
     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
     #
     location ~* \.php$ {
         fastcgi_index   index.php;
         fastcgi_pass    127.0.0.1:9000;
         include           fastcgi_params;
         fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
         fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
     }
  
     # deny access to .htaccess files, if Apache's document root
     # concurs with nginx's one
     #
     #location ~ /\.ht {
     #    deny  all;
     #}
 } 

4、检测配置文件并重新启动nginx服务

[root@2df7fb5c5f50 a.ildd.cc]# nginx -t
 nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
 nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
 [root@2df7fb5c5f50 a.ildd.cc]# nginx -s reload

5、访问测试

至此,安装完成。如有问题请加群讨论。QQ群号:955496382

发表评论

后才能评论