Bad Request (400) when accessing NetBox via reverse proxy #14967
-
Hi I have installed NetBox on Ubuntu 22.04 using apache (without docker). When I access NetBox using the local IP of the VM it works perfectly fine. Next I setup nginx on a OPNsense firewall as a reverse proxy and tried accesssing NetBox via the FQDN, but I get a "Bad Request (400)" all the time. (I triedy ALLOWED_HOST set to '*' and to the FQDN + Local IP.) In the nginx logs there is no error and I got another webserver (Xen Orchestra to be precise) up and running trough the reverse proxy, so I would assume, the error doesn't lie within OPNsense/nginx. I don't really know where to start looking inside of NetBox. What would be the best log file to take a look at and where is it located? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
So you're going via two reverse proxies: nginx and apache? The easiest way to diagnose this is going to be to run tcpdump on the Netbox host to look at traffic to and from gunicorn:
Make an incoming request, look at the headers of the request, and check that the response 400 is being generated from here (which proves it's not Apache or Nginx that's setting the result code to 400). There are a few things which can break here, one of which is that Django barfs if "X-Forwarded-Host" has multiple hosts, e.g.
If that's what you see, then you need to adjust things. I've had Netbox running successfully behind a pair of Apache proxies. On the outer host, I prevented it adding X-Forwarded-Host like this:
Then the inner proxy was able to add a single X-Forwarded-Host, and all was OK. |
Beta Was this translation helpful? Give feedback.
Sorry I missed this:
Ah yes, that's the problem that causes Django to barf.
As a quick fix on the inner Apache (the one on the Netbox server), you could try
(Also, check if the Host: header in tcpdump shows the original FQDN, or the FQDN of the internal Netbox server. Ideally it would be the former. There may be an Nginx setting to tweak for this)