
ubuntu nginx 部署 php 项目时遇到 404 错误如何解决?
在 ubuntu 系统下使用 nginx 部署 php 项目,通常需要进行一些配置。如果您遇到了所有接口都返回 404 错误的情况,可能是配置中存在问题。
检查配置文件
仔细检查您的 conf.d 中的配置是否正确。通常,此文件应包含以下内容:
立即学习“PHP免费学习笔记(深入)”;
server {
listen 80;
server_name www.example.com;
root /var/www/html;
location / {
index index.html index.htm index.php;
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;
}
}重点检查以下部分:
如果以上配置正确,请确保 php-fpm 正在运行,并且端口 9000 已开放。您可以使用以下命令检查:
sudo systemctl status php7.4-fpm
如果仍然遇到问题,请检查以下内容:
如果您通过了所有这些检查,但仍然遇到 404 错误,请尝试重新启动 nginx 和 php-fpm 服务:
sudo systemctl restart nginx sudo systemctl restart php7.4-fpm
以上就是Ubuntu Nginx部署PHP项目时,所有接口都返回404错误该如何解决?的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号