这里是文章模块栏目内容页
cygwin下nginx的web多站点配置及php解析配置

环境:

cygwin2.891;

nginx1.14.0;

php7.1.16


web多站点配置:


步骤一:设置配置文件


方法一:在nginx.conf中添加


复制 server{......} 代码段并粘贴到这个代码段后面,修改站点域名和站点根目录,如下。本地域名:www.test.com;根目录:/srv/www/htdocs/tp/public


方法二:建一个专门的文件夹放站点配置,一个配置文件一个站点,然后在nginx.onf中引入这些配置


建个专门存放站点配置的文件夹(我的放在nginx.onf所在文件夹上级文件夹下,名称为vhost),为www.test.com站点建一个配置文件test.conf,为www.test2.com站点建配置文件test2.conf。如方法一中将 server{...}代码段分别复制到两个配置文件中,并修改本地域名和根目录。然后在nginx.conf配置 http{......}代码段引入站点配置文件。如图


引入站点配置文件:


下面是方法一的完整配置conf 内容

 
#user  Dell owner;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

# Load dynamic modules
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;
  
    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost www.dp2.cn;
  
 root /home/w7swoole/CRMChat-master/crmchat/public;
        index  index.html index.htm index.php;
  
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
  #配置index.php可以省略的方法,thinkphp经常需要。
  location /
  {
    if (!-e $request_filename) {
                    rewrite  ^(.*)$  /index.php?s=/$1  last;
                  }
  } 
      #配置thinkphp-swoole 方法
  location /ws
  {
   proxy_pass http://127.0.0.1:20108;
   proxy_http_version 1.1;
   proxy_read_timeout 360s;   
   proxy_redirect off; 
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection "upgrade";
   proxy_set_header Host $host;
   proxy_set_header X-Real-IP $remote_addr;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header REMOTE-HOST $remote_addr;
   
   add_header X-Cache $upstream_cache_status;   
   #Set Nginx Cache   
   add_header Cache-Control no-cache;
   expires 12h;
   
  }
        #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   html;
        }

        # 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$ {
   #root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
  
  
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}


步骤二:重启nginx服务器

步骤三:在host文件中添加本地站点域名。在浏览器输入站点域名便可以打开。


php解析配置


步骤一:


在上面配置文件的 server{......}段中加入php配置,如下所示




步骤二:


重启nginx服务器。