[Flask] flask url_for / nginx proxy_pass

Pascal patatetom at gmail.com
Fri Jun 10 08:22:08 EDT 2016


if I manually add /flaskbb in layout.html, the link seems good (eg <link
rel="stylesheet" href="/flaskbb/static/css/styles.css"> but flaskbb app
return a 404 to nginx on request :

127.0.0.1 - - [10/Jun/2016 14:18:54] "GET /flaskbb/ HTTP/1.0" 200 -
127.0.0.1 - - [10/Jun/2016 14:18:54] "GET /flaskbb/static/css/pygments.css
HTTP/1.0" 404 -
127.0.0.1 - - [10/Jun/2016 14:18:54] "GET /flaskbb/static/css/styles.css
HTTP/1.0" 404 -


2016-06-10 14:16 GMT+02:00 Pascal <patatetom at gmail.com>:

> thank you for track Ulrich
>
> I've changed the url prefixes defined in default.py
> <https://github.com/sh4nks/flaskbb/blob/master/flaskbb/configs/default.py#L117-121>
> and used in app.py
> <https://github.com/sh4nks/flaskbb/blob/master/flaskbb/app.py#L80-89>
> with register_blueprint.
> I've also changed nginx directive to <code>location /flaskbb/ { proxy_pass
> http://127.0.0.1:8765/flaskbb/; }</code>.
>
> now links are good :-) except static files like css :-(.
>
> for example, this link <link rel="stylesheet"
> href="/static/css/styles.css"> is made with template layout.html
> <https://github.com/sh4nks/flaskbb/blob/master/flaskbb/templates/layout.html#L26>
> by url_for...
>
>
>
> 2016-06-10 12:43 GMT+02:00 Ulrich Berthold <ub at artfacts.net>:
>
>> hey pascal,
>>
>> when using blueprints, you can pass the url prefix as an argument to
>> register_blueprint, like this:
>>
>> app.register_blueprint(api, url_prefix='/api')
>>
>> will make api aceesable under https://my.url/api and urls created with
>> url_for in that context will have the prefix.
>>
>> there is a  stackoverflow question, which i think handles your problem:
>>
>> http://stackoverflow.com/questions/18967441/add-a-prefix-to-all-flask-routes
>>
>> cheers,
>> ub
>>
>>
>> On Fri, Jun 10, 2016 at 11:52:57AM +0200, Pascal wrote:
>> > hello,
>> >
>> > my flask app (flaskbb <https://github.com/sh4nks/flaskbb>) is
>> listening on
>> > 127.0.0.1:8765 and is ok when accessed directly with
>> http://127.0.0.1:8765/.
>> >
>> > when accessed through nginx with http://mywebserver/flaskbb/, all
>> links are
>> > broken because /flaskbb is missing in the url (eg. src="/css/..." and
>> not
>> > src="/flaskbb/css/...").
>> >
>> > I currently bypasses the problem by modifying the templates, but it's
>> not
>> > clean :-(
>> >
>> > how can I solve this problem ?
>> >
>> > note that nginx directive is location /flaskbb/ { proxy_pass
>> > http://127.0.0.1:8765/; } and I can't play with virtual-server/dns.
>>
>> > _______________________________________________
>> > Flask mailing list
>> > Flask at python.org
>> > https://mail.python.org/mailman/listinfo/flask
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20160610/d93b6c0b/attachment-0001.html>


More information about the Flask mailing list