Add support for reverse proxied setups with Gunicorn, and document Gunicorn, uWSGI & NGINX configurations. Fixes #2001

This commit is contained in:
Dave Page
2019-03-04 16:29:25 +00:00
parent 28555b387f
commit f401def044
4 changed files with 164 additions and 1 deletions

View File

@@ -57,6 +57,27 @@ if not os.path.isfile(config.SQLITE_PATH):
)
exec(open(file_quote(setupfile), 'r').read())
##########################################################################
# Support reverse proxying
##########################################################################
class ReverseProxied(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
script_name = environ.get("HTTP_X_SCRIPT_NAME", "")
if script_name:
environ["SCRIPT_NAME"] = script_name
path_info = environ["PATH_INFO"]
if path_info.startswith(script_name):
environ["PATH_INFO"] = path_info[len(script_name):]
scheme = environ.get("HTTP_X_SCHEME", "")
if scheme:
environ["wsgi.url_scheme"] = scheme
return self.app(environ, start_response)
##########################################################################
# Server startup
##########################################################################
@@ -68,6 +89,7 @@ if config.DEBUG:
# Create the app!
app = create_app()
app.wsgi_app = ReverseProxied(app.wsgi_app)
if config.DEBUG:
app.debug = True