R
R
Reanima2020-10-28 17:14:52
Nginx
Reanima, 2020-10-28 17:14:52

NGINX + FLASK + Gunicorn configuration. How to configure proxying to a server subdirectory?

There is a configured VPS with NGINX + Gunicorn + Flask
When accessing the "IP server" the application works.

How can I change the config so that when I access a url like "server IP/python_dev" my application opens?
If I use location /python_dev the error is "Not Found. The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again." when accessing

Nginx config:

server {
  listen 80;

  server_name _;
  
        location / {
                include proxy_params;
                proxy_pass http://unix:/home/it/python_dev/myproject.sock;
        }

}


The application itself
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "<h1 style='color:blue'>Hello There!</h1>"

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


Daemon that runs gunicron
[Unit]
Description=Gunicorn instance to serve myproject
After=network.target

[Service]
User=it
Group=www-data
WorkingDirectory=/home/it/python_dev
Environment="PATH=/home/it/python_dev/env/bin"
ExecStart=/home/it/python_dev/env/bin/gunicorn --workers 3 --bind unix:myproject.sock -m 007 wsgi:app

[Install]
WantedBy=multi-user.target

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-10-28
@bacon

1. it is not clear how Gunicorn works here, where is it described how it interacts with the flask application?
2. flask application is running on 0.0.0.0 and nginx is proxying unix socket

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question