Linux下Nginx配置多个站点

Linux下Nginx配置多个站点

配置多站点实际就是一个主配置文件, 多个子配置文件, 然后在主配置文件中include子配置文件的路径即可

  1. 建立文件夹:eg. /root/wwwroot 即: 站点目录

  2. 建立vhost文件夹(/usr/local/nginx/conf/vhost)

  3. vhost下创建配置文件name.conf

    server {
          listen       80;
          server_name IP;
          root   /home/wwwroot/test;
          location / {
              index index.html index.htm index.php;
              #autoindex on;
          }
          location ~ .php$ {
              fastcgi_pass   127.0.0.1:9000;
              fastcgi_index index.php;
              fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
              include       fastcgi_params;
          }

    }
  4. 配置主配置文件nginx.conf

    http{
      ....
    include vhost/*.conf;
    }
  5. ./nginx -s reload

原文地址:https://www.cnblogs.com/lsb123/p/13884270.html