以下是Debian系统中Nginx常见错误代码及解决方法:
403 Forbidden
www-data
)对目标目录有读取权限:sudo chown -R www-data:www-data /path/to/directory
sudo chmod -R 755 /path/to/directory
。root
或alias
指令是否正确。sudo setenforce 0
(生产环境慎用)。404 Not Found
location
块路径是否正确。413 Request Entity Too Large
nginx.conf
中client_max_body_size
参数(如设置为20M
),并重启Nginx。500 Internal Server Error
/var/log/nginx/error.log
,定位具体错误。sudo systemctl status php-fpm
。502 Bad Gateway / 504 Gateway Timeout
proxy_read_timeout
、proxy_send_timeout
。端口冲突
sudo netstat -tulnp | grep :80
。通用排查步骤:
tail -f /var/log/nginx/error.log
。sudo nginx -t
,修正错误后重启服务:sudo systemctl restart nginx
。若问题仍未解决,可参考Nginx官方文档或社区论坛进一步分析。