Granian http/https problem in Flask app #475
-
I just tried replacing gunicorn with granian for my flask app. Granian sits behind NGINX. Everything works fine, except all my links are now being resolved to http instead of https. I guess because granian sees the request as http://127.0.0.1:port. In gunicorn there is similar problem, but can be resolved by telling NGINX to add the headers below. Granian doesn't seem to treat these headers similarily as gunicorn. There is a possible fix in werkzung, but it's a bit messy, so was wondering if there is anyway to fix this on the granian/nginx level?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
At current time, Granian won't use
def app_https_forw_wrapper(environ, start_response):
if environ.get("HTTP_X_FORWARDED_PROTO") == "https":
environ["wsgi.url_scheme"] = "https"
return actual_app(environ, start_response) |
Beta Was this translation helpful? Give feedback.
At current time, Granian won't use
X-Forwarded
headers to alterwsgi.url_scheme
in WSGI environ, mainly 'cause there's no mention in WSGI spec that such value should be set using the mentioned headers.While we can discuss wether this behavior should be changed in future releases, at the time being this can probably be "fixed" by either:
wsgi.url_scheme
tohttps
, eg: