迁移Laravel项目后出现Nginx 'File Not Found'错误求助
解决Laravel迁移后Nginx "File Not Found" 错误
检查文件与目录权限
- Linux下
/home/user目录默认权限通常是700,会直接阻止Nginx进程(默认用户为www-data)访问内部文件,先调整用户目录权限:sudo chmod 755 /home/user - 确保Nginx对Laravel项目目录及关键子目录有读写权限:
sudo chown -R www-data:www-data /home/user/laravel-project sudo chmod -R 755 /home/user/laravel-project sudo chmod -R 775 /home/user/laravel-project/storage /home/user/laravel-project/bootstrap/cache
验证Nginx配置有效性
- 先检查配置文件语法是否正确,避免因拼写错误导致加载失败:
若提示错误,根据修正后再重启Nginx:sudo nginx -tsudo systemctl restart nginx - 确认配置中的
try_files指令正确指向Laravel入口文件,典型的location配置段应包含:
确保location / { try_files $uri $uri/ /index.php?$query_string; }index.php路径相对于新的root目录是存在的,可手动验证:ls -l /home/user/laravel-project/public/index.php
检查SELinux限制(若启用)
- 如果服务器开启了SELinux,会限制Nginx访问/home目录下的资源,可临时关闭测试:
若关闭后错误消失,需添加永久规则允许Nginx访问该目录:sudo setenforce 0sudo semanage fcontext -a -t httpd_sys_content_t "/home/user/laravel-project/public(/.*)?" sudo restorecon -Rv /home/user/laravel-project/public
内容的提问来源于stack exchange,提问作者Telexx
相关产品推荐
相关产品推荐

