【发布时间】:2018-04-26 00:27:56
【问题描述】:
我在尝试部署我的 Web 服务器时遇到了一个问题,我收到了 502 bad gateway 错误。
查看 nginx 错误日志时,我得到以下信息:
failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xx, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "example.com"
然后我运行sudo netstat -tnlp | grep :8000 来查看端口 8000 上是否有任何东西在监听,但没有输出,这意味着确实没有任何东西在端口 8000 上监听。
另外,这是我在启用站点时的 nginx 配置:
upstream app_server {
server unix:/home/daniel/myproject/myproject.sock fail_timeout=0;
}
server {
listen 80;
server_name 138.197.152.54;
client_max_body_size 50M;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/daniel/myproject;
}
location / {
include proxy_params;
proxy_pass http://127.0.0.1:8000/;
proxy_redirect off;
# proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 30;
proxy_read_timeout 30;
}
我想知道服务器监听的端口是不是假的,因为代理通道有 127.0.0.1:8000,最重要的是,服务器显然正在监听端口 80.
我的配置有问题吗?我对使用 nginx、gunicorn 很陌生,非常感谢在这个问题上提供任何帮助。
【问题讨论】:
-
端口 8000 是
nginx期望gunicorn监听的端口。您似乎将 Unix 套接字与 TCP/IP 套接字混淆了。你的gunicorn配置是什么样的?
标签: django nginx configuration gunicorn bad-gateway