连接到上游时被拒绝连接(nginx + uwsgi) - 集群

Connection Refused while connecting to upstream (nginx + uwsgi) - Clustering

我正在尝试使用 nginx 执行负载平衡。我的 Django 应用程序 运行 位于单独容器中的 uwsgi 和单独容器中的 nginx 后面。 我正在通过端口连接它们。

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format main '$server_name to: $upstream_addr [$request] '
        'upstream_response_time $upstream_response_time '
        'msec $msec request_time $request_time';

    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    upstream uwsgicluster {
       server x.x.x.x:3873;
    }
   server {
        listen 8080;
        server_name mycustom.domain.com;
        location = favicon.ico { access_log off; log_not_found off; }
        location / {
            include uwsgi_params;
            uwsgi_pass uwsgicluster;
      }
   }
}

我在另一台机器上的 uwsgi 配置是 -

[uwsgi]
project = testApp
username = root
base = /data/application/

chdir = %(base)/%(project)
#home = %(base)/Env/%(project)
module = %(project).wsgi:application

master = true
processes = 5

uid = %(username)
gid = %(username)
log-reopen = true
logto = /data/application/logs/uwsgi_error.log
log-maxsize = 20000000
logfile-chown = true
http = 127.0.0.1:3873
vacuum = true

所以我的 nginx 正在监听 8080(单独的容器)而 uwsgi 是 运行 3873(单独的容器)。

现在当我发出请求时,我收到连接被拒绝的错误,如下所示 -

2018/11/19 12:47:32 [error] *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: mycustom.domain.com, request: "GET / HTTP/1.1", upstream: "uwsgi://x.x.x.x:3873", host: "localhost:8080"

我已经将 selinux 设置为宽容模式。 我做错了什么线索? 非常感谢您的帮助!!

经过几个小时的努力,我通过更改 uwsgi 配置解决了这个问题。

我没有使用http参数监听127.0.0.1:3873,而是改为socket参数监听0.0.0.0:3873。

希望这对某人有所帮助:)