Question

Given the configuration below for : Nginx, Uwsgi and Flask.

If I move the Flask application from /test/ to production I must update the Nginx configuration, and preferably only that configuration. So a solution would by if the Flask @app.route('/test/') would be relative, so in a non existing syntax: @app.route('[root]'). I can't find a way to accomplish this. That being said, I presume there 'is' a way because if I must alter all the paths in Flask seems so impracticable.

Nginx:

location /test/ {
    uwsgi_pass      127.0.0.01:3031;
    include         uwsgi_params;
}

Uwsgi:

uwsgi --socket 127.0.0.1:3031 --wsgi-file myflaskapp.py --callable app --proces$

Flask:

from flask import Flask
app = Flask(__name__)
@app.route('/test/')
def index():
    return "<span style='color:red'>I am app 1</span>"

I'm trying to accomplish to move my application to any sub-path of the domain (site.com/apps, site.com/congres/, and so forth) and only to update the NGINX configuration.

Was it helpful?

Solution

You're probably thinking of @app.route('/'). The route URL appears to be absolute, but it is actually relative to the root URL of your application.

This is actually covered in Flask's documentation. You only specify the URL to bind your application to in the nginx configuration; Flask should be able to detect this location from the WSGI environment and build its routes accordingly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top