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

时间:2015-09-18 13:35:08

标签: nginx uwsgi

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

  

2015/09/18 13:03:37 [错误] 32636#0:* 1连接()失败(111:连接被拒绝)连接上游时,客户端:xx.xx.xx.xx,服务器:xx .xx.xx.xx,请求:" GET / HTTP / 1.1",上游:" uwsgi://127.0.0.1:8000",主机:" 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那么它正在工作。

5 个答案:

答案 0 :(得分:2)

我通过更改uwsgi中的套接字配置来解决它 从socket = 127.0.0.1:3031,到socket =:3031。当我在一个docker容器中运行nginx而在另一个容器中运行uwsgi时,我遇到了这个问题。如果你使用命令行启动uwsgi ..然后执行uwsgi --socket:3031。

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

答案 1 :(得分:0)

更改此地址:

include  /home/ubuntu/test_django/uwsgi_params;

include     /etc/nginx/uwsgi_params;

答案 2 :(得分:0)

在我使用debian服务器的情况下,它运行起来了:

include     /etc/nginx/uwsgi_params;

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

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

另外,检查您是否安装了以下软件包: uwsgi-插件-蟒

答案 3 :(得分:0)

pip3 install uWSGI did the trick for me :D

答案 4 :(得分:-1)

当我通过nginx + gunicorn设置env并解决它时遇到了这个问题 添加' *'至ALLOWED_HOSTS或您的特定域名。