Nginx – Basic NGINX, uWSGI configuration running locally only delivers 404

flasknginxuwsgi

My Flask app runs through uWSGI, and I am using a TCP socket to talk to NGINX. The configuration is very basic:

application.conf

server {
    listen 80 default_server;

    location / {
        uwsgi_pass 127.0.0.1:9000;
        include uwsgi_params;
    }
}

I specify the TCP socket in my .ini:

uwsgi.ini

[uwsgi]
socket = 127.0.0.1:9000

# remove the socket once disconnected
vacuum = true

module = wsgi
callable = app
processes = 4
threads = 2
master = 1

And my module:

wsgi.py

from app import create_app

app = create_app('config/development.py')

if __name__ == '__main__':
    app.run()

127.0.0.1:80/ only returns 404 errors (and NGINX 502 errors when uWSGI is not running).

How can I get uWSGI and NGINX to speak to one another? How can uWSGI serve the Flask app through NGINX?

Best Answer

I solved the problem by changing my Flask configuration to specify the server:

config/development.py

...
SERVER_NAME = 'applicationlocal'

and then specified that server in the NGINX configuration:

application.conf

location / {
     listen 80;
     server_name applicationlocal;
}

I had previously edited the OS X host file to match 127.0.0.1 to "applicationlocal"; now I can access the application at "applicationlocal:80/" but not "127.0.0.1:80/".