0

I am trying to deploy a Flask and uwsgi application with Nginx, everything is working and I can get my application to work on my domain: test.example.com:8080.

The problem is I can't make it work under the default port 80, I get the following error message from Nginx when I try to browse test.example.com:

2016/09/02 10:21:29 [error] 2947#2947: *3 no live upstreams while connecting to upstream, client: 75.xxx.xxx.136, server: test.example.com, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://localhost", host: "test.example.com", referrer: "http://test.example.com/"

This is my uwsgi command:

uwsgi --socket 8080 --chdir /var/www/test.example.com --protocol=http --module myapp:app

And this is my Nginx config:

server {

    listen 80;

    root /var/www/test.example.com;
    server_name test.example.com;

    location / {
        include         uwsgi_params;
        uwsgi_pass   0.0.0.0:8080;
    uwsgi_param SCRIPT_NAME /myapp;
    }
}

Nginx can't just pass the traffic to port 8080 from 80 for my server, I don't know why.

Madno
  • 203
  • 4
  • 16

1 Answers1

1

Your uwsgi commandline is wrong. Confirm by checking if you have a file socket called 8080 under /var/www/test.example.com. If it's there, you have mixed up TCP and UNIX sockets.

Also, --protocol http means that you should use HTTP protocol to access uwsgi, not uwsgi's own, which nginx also supports. Remove that option, or use proxy_pass instead of uwsgi_pass.

The correct commandline would be:

uwsgi --socket :8080 --chdir /var/www/test.example.com --module myapp:app

To improve security, you might also want to specify site-local IP for uwsgi to listen on, so use for example 127.0.0.1:8080 instead of just :8080.

One more way to go is to use UNIX sockets instead of listening on tcp/8080 by specifying a socket path for uwsgi command line and use uwsgi_pass unix:/file/path/passed/to/socket in nginx configuration. That would be even more secure, because you can control socket's access rights with directory's permissions, limiting local user's ability to cause harm as well.

korc
  • 126
  • 1
  • Thank you so much for the information bro, I almost got mad because I follow those instructions on the internet and I don't know where the mistake was. It works well now. – Madno Sep 02 '16 at 15:28