Hi Christian,
Sorry for the late reply, other priorities.
I just dove into the code, and managed to fix it.
It actually was an nginx config omission.
It needed the port included in the META tag HTTP_HOST, by doing:
proxy_set_header Host $host:8090;
It might be better to use $port (didn't check the docs) , but this is good enough for us.
If you'd put this as a caveat in the RB docs, it might help other nginx newbees like me.
At runtime I could ask for the django port, but of course that's the wrong one (only used for reverse proxy, not for the site).
So it needs to come from nginx.
I found it by step debugging through Django (quite some code), and hitting this method:
def _get_raw_host(self):
"""
Return the HTTP host using the environment or request headers. Skip
allowed hosts protection, so may return an insecure host.
"""
# We try three options, in order of decreasing preference.
if settings.USE_X_FORWARDED_HOST and (
'HTTP_X_FORWARDED_HOST' in self.META):
host = self.META['HTTP_X_FORWARDED_HOST']
elif 'HTTP_HOST' in self.META:
host = self.META['HTTP_HOST']
else:
# Reconstruct the host using the algorithm from PEP 333.
host = self.META['SERVER_NAME']
server_port = self.get_port()
if server_port != ('443' if self.is_secure() else '80'):
host = '%s:%s' % (host, server_port)
return host
Served by apache, the else was entered. Which isn't technically valid when running the WSGI as a reverse proxy. One of the two META tags is needed.
It all makes sense now.
Kind regards, TW