You are not logged in.

#1 2017-05-26 20:23:59

vlast777
Member
Registered: 2015-02-10
Posts: 57

[nginx + gunicorn] Deploy multiple Flask apps

Hey there,

I am trying to set up nginx + gunicorn on my Arch Linux server to run multiple Flask apps. However I am seemingly failing in configuring nginx the right way to do so.

When I just got one Flask app up and running everything seems to work fine. I included the /etc/nginx/sites-available and /etc/nginx/sites-enabled in my /etc/nginx/nginx.conf.

I created a file "flask_settings" inside /etc/nginx/sites/available and linked it to /etc/nginx/sites-enabled. The file looks like this:

server {
        location /{
                proxy_pass http://127.0.0.1:8000;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;

}


}

I have a folder containing my Flask app (sample App, hellp.py) which i run with gunicorn in a virtual environment. I just run it using

gunicorn hello:app

If i visit my servers IP I can access the file and the different routes.

Now I tried to set up another app creating another file in /etc/nginx/sites-enabled called flask2. It looks like this:

server {
        location /hello {
                proxy_pass http://127.0.0.1:8001;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;

}


}

I then try to run the app inside its very own virtual environment with

gunicorn --bind 127.0.0.1:8001 hello:app

When I restart nginx afterwards, I am still able to access the first app and all of its routes, but if I try to access the other one by entering my servers IP + the router (after the "/"), nginx always tells me, that the sites cannot be found. Am I missing anything here?

Any help is highly appreciated.

Thanks in advance!

Offline

#2 2017-10-07 22:06:22

drinotidip
Member
Registered: 2017-10-07
Posts: 1

Re: [nginx + gunicorn] Deploy multiple Flask apps

Not sure if you solved your issue but I followed the steps on this guide to setup nginx+gunicorn for a flask app

I think you need to specifcy the socket using --bind 0.0.0.0:8000
I think you got a 404 since you are missing the servername in nginx or you have /etc/nginx/sites-enables that conflicts with your site.

Offline

Board footer

Powered by FluxBB