ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
nginx.conf的http下配置 ``` include vhosts/*.conf; ``` 然后在vhosts文件夹下的xxx.conf文件下配置各个网站的server ### **0localhost_80.conf** ``` server { listen 80; server_name localhost; root "D:/PRO/phpstudy_pro/WWW"; location / { index index.php index.html; error_page 400 /error/400.html; error_page 403 /error/403.html; error_page 404 /error/404.html; error_page 500 /error/500.html; error_page 501 /error/501.html; error_page 502 /error/502.html; error_page 503 /error/503.html; error_page 504 /error/504.html; error_page 505 /error/505.html; error_page 506 /error/506.html; error_page 507 /error/507.html; error_page 509 /error/509.html; error_page 510 /error/510.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; } } ``` ### **www.chat.com_80.conf** ``` server { listen 80; server_name www.chat.com; root "D:/PRO/phpstudy_pro/WWW/www.chat.com/public"; location / { index index.php index.html error/index.html; error_page 400 /error/400.html; error_page 403 /error/403.html; error_page 404 /error/404.html; error_page 500 /error/500.html; error_page 501 /error/501.html; error_page 502 /error/502.html; error_page 503 /error/503.html; error_page 504 /error/504.html; error_page 505 /error/505.html; error_page 506 /error/506.html; error_page 507 /error/507.html; error_page 509 /error/509.html; error_page 510 /error/510.html; include D:/PRO/phpstudy_pro/WWW/www.chat.com/public/nginx.htaccess; 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; } } ``` ## **额外配置去掉入口文件index.php** D:/PRO/phpstudy_pro/WWW/www.chat.com/public/nginx.htaccess ``` if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$1 last; } ``` ``` #检查请求的文件或目录是否存在,如果不存在,则将请求重写到 index.php,并将原始 URL 路径作为 s 参数传递给 index.php #例如: #请求的 URL:http://www.paiadmin.com/admin/login/login #重写后的 URL:http://www.paiadmin.com/index.php?s=admin/login/login location / { if (!-e $request_filename){ rewrite ^(.*)$ /index.php?s=$1 last; break; } } #if 指令在 Nginx 中性能较差,尤其是在高并发场景下,建议使用 try_files 指令替代 if,因为 try_files 的性能更好。 #last 和 break 同时使用是多余的,因为 last 已经会停止处理当前的重写规则 #解释: #try_files:按顺序检查文件或目录是否存在,如果都不存在,则重写到最后一个参数。 #$uri:检查请求的文件是否存在。 #$uri/:检查请求的目录是否存在。 #/index.php?s=$uri:如果文件和目录都不存在,则将请求重写到 index.php,并将原始 URL 路径作为 s 参数。 location / { try_files $uri $uri/ /index.php?s=$uri; } #location / { # if (!-e $request_filename) { # rewrite ^(.*)$ /index.php?s=/$1 last; # } #} ``` ### **www.stp6.com_80.conf** ``` server { listen 80; server_name www.stp6.com; root "D:/PRO/phpstudy_pro/WWW/www.stp6.com/public"; location / { index index.php index.html error/index.html; error_page 400 /error/400.html; error_page 403 /error/403.html; error_page 404 /error/404.html; error_page 500 /error/500.html; error_page 501 /error/501.html; error_page 502 /error/502.html; error_page 503 /error/503.html; error_page 504 /error/504.html; error_page 505 /error/505.html; error_page 506 /error/506.html; error_page 507 /error/507.html; error_page 509 /error/509.html; error_page 510 /error/510.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; } } ```