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

时间:2018-11-19 12:21:12

标签: nginx cluster-computing uwsgi

我正在尝试使用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设置为许可模式。 有什么线索我做错了吗? 真的很感谢帮助!

1 个答案:

答案 0 :(得分:1)

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

我没有使用http参数来监听127.0.0.1:3873,而是将其更改为socket参数,并使其监听了0.0.0.0:3873。

希望这对某人有帮助:)