uWSGI nginx错误:connect()失败(111:连接被拒绝),同时连接到上游

我在访问nginx上的IP时遇到了502个网关错误( http://52.xx.xx.xx/ ),日志只是这样说的:

2015/09/18 13:03:37 [error] 32636#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: xx.xx.xx.xx, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8000", host: "xx.xx.xx.xx" 

我的nginx.conf文件

 # the upstream component nginx needs to connect to upstream django { # server unix:///path/to/your/mysite/mysite.sock; # for a file socket server 127.0.0.1:8000; # for a web port socket (we'll use this first) } # configuration of the server server { # the port your site will be served on listen 80; # the domain name it will serve for server_name xx.xx.xx.xx; # substitute your machine's IP address or FQDN charset utf-8; access_log /home/ubuntu/test_django/nginx_access.log; error_log /home/ubuntu/test_django/nginx_error.log; # max upload size client_max_body_size 75M; # adjust to taste # Django media location /media { alias /home/ubuntu/test_django/static/media/; # your Django project's media files - amend as required } location /static { alias /home/ubuntu/test_django/static/; # your Django project's static files - amend as required } # Finally, send all non-media requests to the Django server. location / { uwsgi_pass django; include /home/ubuntu/test_django/uwsgi_params; # the uwsgi_params file you installed } } 

有没有什么错误的nginx.conf文件…..如果我使用默认的conf然后它工作。

改变这个地址:

 include /home/ubuntu/test_django/uwsgi_params; 

 include /etc/nginx/uwsgi_params; 

我在nginx + gunicorn设置env时遇到了这个问题,通过给ALLOWED_HOSTS或者你的特定域添加'*'来解决这个问题。

我解决了这个问题,将uwsgi中的套接字配置从socket = 127.0.0.1:3031更改为socket =:3031。 当我在一个docker容器中运行nginx并在另一个docker容器中运行uwsgi时,我遇到了这个问题。 如果您使用命令行来启动uwsgi,则执行uwsgi –socket:3031。

希望这可以帮助有人在使用docker部署django应用程序时遇到同样的问题。

在我使用debian服务器的情况下,

 include /etc/nginx/uwsgi_params; 

在我的nginx服务器配置文件中的位置标记,如下所示:

 location /sistema { include /etc/nginx/uwsgi_params; uwsgi_pass unix://path/sistema.sock; } 

另外,请检查您是否安装了以下软件包:uwsgi-plugin-python