Debian系统下Nginx出现502错误,可按以下步骤排查解决:
systemctl status <服务名>确认上游服务(如PHP-FPM、Tomcat)是否运行。curl http://上游服务器地址或telnet 上游IP 端口测试服务是否可达。/etc/nginx/nginx.conf及虚拟主机配置中proxy_pass是否正确指向上游服务器,超时时间(proxy_connect_timeout等)是否合理。/var/log/nginx/error.log,定位具体错误(如“Connection refused”“upstream timed out”)。ping、traceroute测试网络连通性,telnet或nc检查端口是否开放。ufw或iptables),确保Nginx与上游服务器的通信端口未被拦截。top、htop查看CPU/内存使用情况,若资源不足需优化或扩容。ulimit -n,必要时调整/etc/security/limits.conf。sudo nginx -t测试语法,sudo systemctl reload nginx重新加载配置。sudo systemctl restart nginx。参考来源: