I am moving a Flask application from a apache2 and mod_wsgi environment to Nginx, and am having problems getting the urls to work correctly.
I want the root page of my app to appear at, for example, http://example.org/myapp/
My @app.route decorators are e.g. @app.route('/')
for the root of my app (http://example.org/myapp
) and @app.route('/subpage')
for subpages like http://example.org/myapp/subpage
.
Under apache this all "just worked" and my calls to url_for()
produced URLS that got the job done.
Now my URLs from url_for()
are in the form: href="/subpage"
, which is sending me to the domain root, http://example.org/subpage
instead of what I wanted: href="./subpage"
, which would bring me to http://example.org/myapp/subpage
.
For what it's worth, the relevant section from my Nginx config is:
location /myapp/ {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_pass http://127.0.0.1:8001/;
}
I am serving the application with gunicorn.
With the situation as it stands, visiting http://example.org/myapp/
brings me to the root page of my Flask application, but all other URLs bring me back to the domain level: http://example.org/subpage
.
I have tried setting APPLICATION_ROOT to "/myapp", but it seems to have no effect. What am I doing (horribly) wrong?