flask behind gunicorn and apache returning http
1,603
Thanks to the curl output I figured out what the problem is:
RequestHeader set X-Forwarded-Proto "https"
inside the apache config will solve it. Don't forget to enable it (like I did):
a2enmod headers
Related videos on Youtube
Author by
hans2k6
Updated on December 04, 2022Comments
-
hans2k6 over 1 year
I wanted to make my app (finally) accessible through a reserved proxy:
Request --> Apache --> gunicorn --> flask
After reading tons of thread and spending hours on this my actual apache config is:
<IfModule mod_ssl.c> <VirtualHost *:443> ServerName app.%my domain name%.com ProxyPreserveHost On SSLProxyEngine On ProxyPass / http://flask-server:8000/ ProxyPassReverse / http://flask-server:8000/ SSLCertificateFile /etc/letsencrypt/live/app.%my domain name%.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/app.%my domain name%.com/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost> </IfModule>
I am using flask fixproxy, as it should have fixed the issue. But it didn't:
[...] from werkzeug.contrib.fixers import ProxyFix login = LoginManager() login.login_view = 'auth.login' login.login_message = _l('Please log in to access this page.') mail = Mail() bootstrap = Bootstrap() def create_app(config_class=Config): app = Flask(__name__) app.wsgi_app = ProxyFix(app.wsgi_app) app.config.from_object(config_class) [...]
I added to all url_for
_external=True, _scheme='https'
which is working fine, but the app is still forwarding me to http at some places where I cannot add this properties (for example when I am not logged in).I made two checks: 1)
curl -Ik https://app.%my domain name%.com HTTP/1.1 302 FOUND Date: Thu, 19 Apr 2018 22:07:31 GMT Server: gunicorn/19.7.1 Content-Type: text/html; charset=utf-8 Content-Length: 247 Location: http://app.%my domain name%.com/auth/login?next=%2F Set-Cookie: session=... HttpOnly; Path=/
2)
curl -Ik -H "X-Forwarded-Proto: https" https://app.%my domain name%.com HTTP/1.1 302 FOUND Date: Thu, 19 Apr 2018 22:07:22 GMT Server: gunicorn/19.7.1 Content-Type: text/html; charset=utf-8 Content-Length: 247 Location: https://app.%my domain name%.com/auth/login?next=%2F Set-Cookie: session=... HttpOnly; Path=/
Seems like its more a apache problem. Where is my mistake?
-
Admin over 8 yearsHave you fixed this?
-
-
Sant14 over 11 yearsjust wait let me check..
-
Sant14 over 11 yearsHave you logged in as an Administrator?
-
Serious over 11 years
-
Sant14 over 11 yearshey did u check?
-
Serious over 11 yearsI had followed same video. There is toolbar.bmp in MPC folder but still not working.
-
Serious over 11 years
-
Admin over 8 yearsThat worked for me in the past in Windows 7. The question is about Windows 8. I can say that after installing MPC-HC 1.7.9 in Windows 10, the installation folder is C:\Program Files\MPC-HC, but there is no toolbar file there and copying a custom one there doesn't change anything. Or is it because of a MPC update change? -
-
Admin over 8 years- Have you tested your answer in Windows 8 and above?