-
Notifications
You must be signed in to change notification settings - Fork 54
Description
I learned something today about reverse proxy setups...
# our docs at https://rdmo.readthedocs.io/en/latest/deployment/gunicorn.html
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_pass http://unix:/run/gunicorn/rdmo/rdmo.sock;
}
is not ideal, because it sets the Host header to the original host header. X-Forwarded-For is the orginal IP and X-Forwarded-Proto is e.g. https.
Better would be
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $http_host;
proxy_pass http://unix:/run/gunicorn/rdmo/rdmo.sock;
}
which sets the X-Forwarded-Host header. For this to work USE_X_FORWARDED_HOST = True needs to be true in the RDMO settings.
For the gunicorn setup it even works when the proxy_set_header are omitted, since I introduced https://github.com/rdmorganiser/rdmo/blob/main/rdmo/core/settings.py#L7, and the host when running gunicorn locally is ... localhost.
Django sets the "local" allowed hosts automatically when DEBUG = True (https://github.com/rdmorganiser/rdmo/blob/main/rdmo/core/settings.py#L7) so we should remove this settings again.
USE_X_FORWARDED_HOST = True is not needed when running RDMO in Apache so we should not add it to RDMO by default. I think we should add it to rdmo-app and document it properly, but there could be some inconveniences for instances.