Nginx uwsgi flask rewrite directory as base directory within app

nginxpythonuwsgi

So I have a flask application running using uWSGI on Nginx. Nginx is set to call my app at the location /app. So in my flask application I have to take into account the /app part when I map the url to a function. Is there a way to rewrite the nginx file or the uwsgi config.xml file to have the application think it is running from the / directory? And are there any side effects?

Just as an example:

the page http://mysite.com/app/ links to my index.py module

my index.py module uses Flask, so the route mapping goes like this:

@app.route('/app/')
    def hello_world():
        return 'Hello World!'

I am wondering if I can change the config files so I could write:

@app.route('/')
   def hello_world():
       return 'Hello World!'

Instead?

Best Answer

Mount your app in the subdir in uWSGI with

--mount /app=myfile.py --callable app --manage-script-name

it should work without modifying code or using wsgi middlewares