502现象:8000端口无法跳转到服务器上
故障现象
时间: 2025-11-25 21:10
现象:客户机访问 curl -k https://www.hansir.com 出现 502

排查路径
1.查看错误日志
cat /var/log/nginx/https_error.log

通过日志可知:Nginx 无法建立到上游服务器的连接,连接被拒绝
2.检查上游服务器
netstat -tlnp | grep :8000 发现端口号为 127.0.0.1:8000

3.将端口号修改为 0.0.0.0:8000

其中 nginx + python 修改端口方法
ps aux | grep gunicorn
pkill -f gunicorn
ps aux | grep gunicorn
cd /var/www/python-app
gunicorn -b 0.0.0.0:8000 -w 4 your_app:app --daemon
vim /etc/systemd/system/python-app.service
systemctl daemon-reload
systemctl restart python-app.service
cd /etc/nginx/conf.d/
vim python-app.conf
systemctl daemon-reload
systemctl restart python-app.service



错误原因是
127.0.0.1:8000 - 只绑定到本地回环,所以从主服务器上无法跳转到内网服务器上
0.0.0.0:8000 - 监听所有网络接口

浙公网安备 33010602011771号