[Flask] urls when running under gunicorn

Corey Boyle coreybrett at gmail.com
Tue Oct 13 21:00:33 CEST 2015

I think what you are looking for is the "APPLICATION_ROOT" config item.

But don't take my word for it.

On Tue, Oct 13, 2015 at 1:26 PM, S McGraw <smcg4191 at mtneva.com> wrote:
> I new to flask and have a small first app working under flask's
> development server.  In the templates I used url_for(), under the
> impression that would adjust the app's urls when I later run it
> behind a web server.
> I have now gotten it to run under gunicorn and set up a reverse
> proxy to it in my Apache (2.4) web server.  It worked ok when
> configured as a virtual host.  However, I want to run my app under
> a url in my regular url namespace, eg:
>   http://myhost.com/myapp/(login,main,etc...)
> The trouble is that the urls in the rendered templates are still
> "/login", "/main", etc rather than /myapp/login, /myapp/main, etc
> which of course result in a 404 when clicked on.  So I'm sure there
> is some step or piece of code I'm missing.
> FWIW, I tried using the werkzeug ProxyFix middleware suggested in
> the "Proxy Setups" section of the Flask docs, no effect.  I saw
> recommendations to use Flask Snippets #35, along with configuring
> the web server to send certain headers, but they all seemed to be
> for Nginx, and seemed an awfully heavy-weight answer.  Surely there
> is a simpler flask-only way to fix this?  Also I read about Apache's
> mod_proxy_html but that too seems a little overkill to me.)
> I did get things to work by losing the url_for()'s in my code and
> templates, replaced with eg, g.prefix+'/main', where g.prefix is set
> to "/myapp" in a before_request() function. But I don't think that's
> the recommended practice. ;-)
> What am I missing?
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask

More information about the Flask mailing list