学习文章要努力,但是不要急!今天的这篇文章《Ubuntu Nginx部署PHP项目返回404错误:如何正确配置fastcgi_split_path_info和SCRIPT_FILENAME?》将会介绍到等等知识点,如果你想深入学习文章,可以关注我!我会持续更新相关文章的,希望对大家都能有所帮助!

ubuntu nginx 部署 php 项目无法访问 404 错误疑难解答
某位开发者反映在 ubuntu 系统下使用 nginx 部署 php 8088 端口服务时,遇到了全部接口返回 404 错误的问题。
经过分析,发现问题可能出在其 conf.d 下的配置文件中。具体如下:
server {
listen 80;
server_name www.h5fiction1.com;
root "d:/project/h5_fiction_1/public";
location / {
index index.html index.htm index.php;
#autoindex on;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#下面两句是给fastcgi权限,可以支挿?s=/module/controller/action的url访问模式
fastcgi_split_path_info ^(?u).+\.php
fastcgi_param script_filename $document_root$fastcgi_script_name;
#下面两句才能真正支持 index.php/index/index/index的pathinfo模式
fastcgi_param path_info $fastcgi_path_info;
fastcgi_param path_translated $document_root$fastcgi_path_info;
include fastcgi_params;
}
}问题的关键在于 /location~.php(.*)$ 块中的两行配置:
fastcgi_split_path_info ^(?u).+\.php fastcgi_param script_filename $document_root$fastcgi_script_name;
正确配置应该是:
fastcgi_split_path_info ^((?u).+\.php)(/?.+)$; fastcgi_param script_filename $document_root$fastcgi_script_name;
修改后,参考完整的配置文件:
server {
listen 80;
server_name www.h5fiction1.com;
root "D:/project/h5_fiction_1/public";
location / {
index index.html index.htm index.php;
#autoindex on;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#下面两句是给fastcgi权限,可以支挿?s=/module/controller/action的url访问模式
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#下面两句才能真正支持 index.php/index/index/index的pathinfo模式
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于文章的相关知识,也可关注golang学习网公众号。
本文内容来源于互联网,如有侵权请联系删除。
