polo
polo

Reputation: 1442

How does nginx works with uWSGI running a Flask app?

I'm very new to python, to nginx and to flask, so take my understanding of things I describe, with a grain of salt.

I'm looking at a setup of a flask app and nginx before it. The way I understand it, the nginx server, facing the web, behind it behind is a flask app which runs on an uWSGI server.

I see the upstream, the server and the locations configured for nginx. So I know which route is mapped to what internal port.

I'm trying to find where to configure the port for the flask app / uWSGI server. In the logs I see: uWSGI http bound on :8080 fd 4 but when checking with netstat I don't see port 8080 bound

On which port do nginx and the uWSGI server / flask app pass requests? Where is that port configured?

Thanks!

Upvotes: 1

Views: 613

Answers (1)

davidism
davidism

Reputation: 127180

You configure the port or local socket to use using the --socket option (or related config file value).

[uwsgi]
master = true
processes = 8
threads = 2
socket = /home/sopython/uwsgi.sock
vacuum = true
chdir = /home/sopython
virtualenv = /home/sopython
module = sopy:create_app()

Then you configure nginx to communicate with the port or socket you chose.

server {
    listen 80 default_server;
    listen [::]:80 ipv6only=on default_server;
    server_name sopython.com;
    root /home/sopython;
    
    location /static {
        alias /home/sopython/lib/python3.4/site-packages/sopy/static;
    }
    
    location / {
        include uwsgi_params;
        uwsgi_param HTTP_HOST $server_name;
        uwsgi_pass unix:///home/sopython/uwsgi.sock;
    }
}

This was taken from the Python chat room's website configuration.

Upvotes: 2

Related Questions