librelist archives

« back to archive

Flask, reverse proxies and request.url

Flask, reverse proxies and request.url

From:
Adrian Ratnapala
Date:
2012-07-14 @ 16:24
The discussion about mod_wsgi has reminded me of a problem I had last
week: request.url and request.base_url don't know about the port
number of my reverse proxy.

My Flask application is on port 5000 and is made available using Nginx
as a reverse proxy.  However (until last week) nginx was listening on
port 8000, but Werkzeug & Flask ignore this.  Now that it listens on
port 80, everything is fine.

I suspect this is not really Flask's fault, because the WSGI
environment doesn't seem to include the number "8000" anywhere (except
in HTTP_REFERER, but that means something else)



-- 
Adrian Ratnapala
mobile: +49 1515 277 0000

NGBitS GmbH
Rainer Strasse 7
83104 Ostermünchen

Web: www.ngbits.com

Re: [flask] Flask, reverse proxies and request.url

From:
Simon Sapin
Date:
2012-07-14 @ 16:47
Le 14/07/2012 18:24, Adrian Ratnapala a écrit :
> The discussion about mod_wsgi has reminded me of a problem I had last
> week: request.url and request.base_url don't know about the port
> number of my reverse proxy.
>
> My Flask application is on port 5000 and is made available using Nginx
> as a reverse proxy.  However (until last week) nginx was listening on
> port 8000, but Werkzeug & Flask ignore this.  Now that it listens on
> port 80, everything is fine.
>
> I suspect this is not really Flask's fault, because the WSGI
> environment doesn't seem to include the number "8000" anywhere (except
> in HTTP_REFERER, but that means something else)

Hi,

The work-around for such cases is to have a WSGI middleware that fixed 
the environ. The Flask docs on deployment have a some examples of such 
middleware (but maybe to fix SCRIPT_NAME rather than the port number.)

Maybe you could add this example to the deployment docs if it is not 
there already.

-- 
Simon Sapin

Re: [flask] Flask, reverse proxies and request.url

From:
Adrian Ratnapala
Date:
2012-07-14 @ 19:09
> The work-around for such cases is to have a WSGI middleware that fixed
> the environ. The Flask docs on deployment have a some examples of such
> middleware (but maybe to fix SCRIPT_NAME rather than the port number.)
>
> Maybe you could add this example to the deployment docs if it is not
> there already.
>

Thanks!

My workaround was just to move the server to port 80, and that's good
enough for me.  If its a quick job I might try to out your suggestion,
but I can't make any promises.



-- 
Adrian Ratnapala
mobile: +49 1515 277 0000

NGBitS GmbH
Rainer Strasse 7
83104 Ostermünchen

Web: www.ngbits.com