chg: Properly handle proxied setups

pull/79/head
Raphaël Vinot 2020-04-22 14:58:01 +02:00
parent a39f857216
commit ccd73c302a
3 changed files with 19 additions and 1 deletions

View File

@ -7,7 +7,7 @@ server {
proxy_set_header Host $http_host; proxy_set_header Host $http_host;
proxy_redirect off; proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme; proxy_set_header X_FORWARDED_PROTO $scheme;
proxy_connect_timeout 300; proxy_connect_timeout 300;
proxy_read_timeout 300; proxy_read_timeout 300;
proxy_pass http://localhost:5100/; proxy_pass http://localhost:5100/;

View File

@ -16,12 +16,14 @@ from flask_httpauth import HTTPDigestAuth # type: ignore
from lookyloo.helpers import get_homedir, update_user_agents, get_user_agents from lookyloo.helpers import get_homedir, update_user_agents, get_user_agents
from lookyloo.lookyloo import Lookyloo from lookyloo.lookyloo import Lookyloo
from lookyloo.exceptions import NoValidHarFile from lookyloo.exceptions import NoValidHarFile
from .proxied import ReverseProxied
from typing import Tuple from typing import Tuple
import logging import logging
app: Flask = Flask(__name__) app: Flask = Flask(__name__)
app.wsgi_app = ReverseProxied(app.wsgi_app)
secret_file_path: Path = get_homedir() / 'secret_key' secret_file_path: Path = get_homedir() / 'secret_key'

16
website/web/proxied.py Normal file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class ReverseProxied():
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
scheme = environ.get('HTTP_X_FORWARDED_PROTO')
if not scheme:
scheme = environ.get('HTTP_X_SCHEME')
if scheme:
environ['wsgi.url_scheme'] = scheme
return self.app(environ, start_response)