PHP程序员

nginx设置站点

2020-12-17  本文已影响0人  php转go

找到nignx的配置文件nginx.conf
在配置文件,找到http,每设置一个站点,就增加一个server

以下是windows系统下的nginx的server配置

http {
server {
        listen        80;#监听端口
        server_name  vivo.test; #域名
        root   "D:/xcx/public/"; #站点目录
        location / {
          if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
            }
            index index.php index.html error/index.html;
            autoindex  off;
        }
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
}
}

Linux系统下的server配置

server {
        listen  80;
        server_name 52.15.186.82;#域名
        index index.html index.htm index.php;
        root  /data/www/default/public;#域名指向目录
    
    location ~  ^/public {
            root /data/www/html;
        add_header Access-Control-Allow-Origin *;
        }
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
        location ~* \.ttf$ {
            add_header Access-Control-Allow-Origin *;
        }
        location / { # …..省略部分代码
           if (!-e $request_filename) {
           rewrite  ^(.*)$  /index.php?s=/$1  last;
           break;
            }
         }
        location ~ \.php$
        {
                index index.php;
                try_files $uri =404;
                fastcgi_pass    unix__tmp_php_cgi_sock;
                include         fastcgi_params;
                fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param   SCRIPT_NAME $fastcgi_script_name;
        }

        #access_log  /data/logs/www/www.test.com.log  snlog;
}

也可以自定义一个文件夹,包含里面的conf文件
每个站点设置一个xxx.com.conf,每个conf文件对应一个sever

http{
include vhosts/*.conf;
}
上一篇下一篇

猜你喜欢

热点阅读