nginx 配置一个或者多个域名
cd etc/nginx/ 进入到nginx目录
vi nginx.conf
server 一个为例
server { listen 80 default_server; #listen [::]:80 default_server; server_name www.***.com; root /home/tt/public; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { index index.html index.htm index.php; #autoindex on; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } location ~ .*.php?$ { # 设置监听端口 fastcgi_pass 127.0.0.1:9000; # 设置nginx的默认首页文件(上面已经设置过了,可以删除) fastcgi_index index.php; #fastcgi_split_path_info ^(.+\.php)(.*)$; #增加这一句 fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; #增加这一句 # 设置脚本文件请求的路径 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param SCRIPT_FILENAME /home$fastcgi_script_name; # 引入fastcgi的配置文件 include fastcgi_params; } }
添加多个复制放到下方绑定不同的域名和项目路径即可
server { listen 80; #listen [::]:80 default_server; server_name www.xxx.com; root /home/new/public; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { index index.html index.htm index.php; #autoindex on; if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; break; } } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } location ~ .*.php?$ { # 设置监听端口 fastcgi_pass 127.0.0.1:9000; # 设置nginx的默认首页文件(上面已经设置过了,可以删除) fastcgi_index index.php; #fastcgi_split_path_info ^(.+\.php)(.*)$; #增加这一句 fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; #增加这一句 # 设置脚本文件请求的路径 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fastcgi_param SCRIPT_FILENAME /home$fastcgi_script_name; # 引入fastcgi的配置文件 include fastcgi_params; } }
配置完成后记得重新启动nginx
service nginx restart