0
votes

I am trying to do perform load balancing using nginx. My Django application is running behind uwsgi which is in separate container and nginx in separate container. I am connecting them over port.

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;
      }
   }
}

My uwsgi configuration on the other machine is -

[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

So my nginx is listening to 8080(separate container) and uwsgi is running 3873(separate container).

Now when i make request I get connection refused error as below -

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"

I have set the selinux to permissive mode. Any clues where I am doing wrong ? Help is really appreciated !!

1

1 Answers

2
votes

After struggling for hours,I resolved the issue by changing the uwsgi configuration.

Instead of using http parameter listening to 127.0.0.1:3873, I changed it to socket parameter and made it listen to 0.0.0.0:3873.

Hope this helps someone :)