0

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?

  • 1
    Check your error log. – Michael Hampton Feb 13 '17 at 18:43
  • error.log gives me: [notice] 4xxxx#0: signal process started – llater Feb 14 '17 at 1:16
  • 1
    I solved the problem by setting the Flask config "SERVER_NAME" to a domain configured in my OS X host file "applicationlocal", and then changed my application.conf to: listen 80; server_name applicationlocal. Hope this helps someone! – llater Feb 14 '17 at 3:21
  • 1
    @LelandLater Please write it as an answer, even if it's ur own question. – Piotr Dawidiuk Feb 14 '17 at 14:07
2

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/".

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.