Niginx +fastCGI,配置
404 Not Found
nginx/1.19.4
原因:
对于ThinkPHP的URL访问路径,如:http://域名/index.php/Index/index/index,原先的Nginx的是不支持的pathinfo路径的,导致你在thinkPHP5上面测试的时候,输入相应的URL也不会提示模块名,控制器名或者方法名错误,而是出现一个404找不到的错误,那是因为Nginx无法解析这样的链接
方案
配置 Nginx 使其支持 PHP 应用:
vim /usr/local/nginx/conf/nginx.conf
修改默认的 location 块,使其支持 .php 文件:
location / {
root html;
index index.php index.html index.htm;
}
下一步配置来保证对于 .php 文件的请求将被传送到后端的 PHP-FPM 模块, 取消默认的 PHP 配置块的注释,并修改为下面的内容:
location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
重启 Nginx
% nginx -s reload
通过以上步骤的配置,Nginx 服务器现在可以以 SAPI
SAPI
模块的方式支持 PHP 应用了。 当然,对于 Nginx 和 PHP 的配置
需要带index.php
http://localhost:8080/项目名/public/index.php/控制器/类/方法