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

8

访问nginx(http://52.xx.xx.xx/)时,我遇到了502网关错误,日志只是简单地显示:

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文件有什么问题吗?


1
请发布您的uWSGI配置。 - mergenchik
你找到答案了吗? - mergenchik
2
我使用了Unix套接字... - FlyingHeem
2
遇到了相同的问题...您能否详细说明一下...如果您已经解决了这个问题...提前感谢。 - DRY Believer
安装PCRE库解决了我的问题: https://dev59.com/m2Ei5IYBdhLWcg3wFou9 - vfinn
5个回答

7
我通过更改uwsgi.ini中的套接字配置来解决了这个问题,将socket = 127.0.0.1:3031更改为socket = :3031。当我在一个Docker容器中运行nginx和另一个uWSGI时,我遇到了这个问题。如果您使用命令行启动uWSGI,则执行uwsgi --socket :3031
希望这可以帮助那些在使用Docker部署Django应用程序时遇到相同问题的人。

我在哪里可以找到uwsgi.ini文件?我找不到它。或者我应该创建它,它应该放在哪里? - itTech
@itTech 它不会被称为 uwsgi.ini,而是将被称为 <your_app>.ini。在此处阅读更多信息:https://uwsgi-docs.readthedocs.io/en/latest/Configuration.html#ini-files - David Maness

0

更改此地址:

include  /home/ubuntu/test_django/uwsgi_params;

include     /etc/nginx/uwsgi_params;

-1

pip3 install uWSGI 对我来说解决了问题 :D


-1

我在使用nginx + gunicorn设置环境时遇到了这个问题,通过将'*'添加到ALLOWED_HOSTS或您的特定域名中解决了它。


-1
在我的情况下,使用Debian服务器,将其移动是有效的:
include     /etc/nginx/uwsgi_params;

在我的nginx服务器配置文件的location标签中,像这样:
location /sistema {
    include     /etc/nginx/uwsgi_params;
    uwsgi_pass  unix://path/sistema.sock;
}

请确认以下软件包已安装: uwsgi-plugin-python

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接