Nginx proxy headers and checking API token allowed IPs #14652
Replies: 1 comment 3 replies
-
Apache uses However there is a wrinkle with multiple proxies, at least last time I checked this (a year or so back). If you go through multiple proxies and Apache sets So I use the following on the outer proxy so that only X-Forwarded-For is set, and the Host header contains the original target host:
The inner proxy can then set X-Forwarded-Host, and/or add another IP address to X-Forwarded-For, and things work. |
Beta Was this translation helpful? Give feedback.
-
Current NetBox-default nginx.conf suggests this:
That
$remote_addr
there is the source IP of the connection Nginx receives. In basic cases that is the NetBox API client's IP address.This works for API token allowed IP list.
Now, if you are running your NetBox instance behind another reverse proxy, like a load balancer, the
X-Real-IP
header is populated with the load balancer IP address. In that case the API token allowed IP check fails if you try to use the API client IP there.Idea: Set the
X-Real-IP
header with$proxy_add_x_forwarded_for
like this:I don't know all the details of
$proxy_add_x_forwarded_for
but it seems to work for the basic case (= no additional reverse proxy/load balancer, the client connects directly to NetBox' Nginx) just fine.The beauty of using
$proxy_add_x_forwarded_for
seems to appear when using the additional reverse proxy/load balacer in front of NetBox' Nginx. The header now looks like this:Now the API token allowed IP check works as well: if I configure the token with only 192.168.1.1/32 allowed, I get the error message when accessing the API:
But, if I allow the client IP 172.16.16.162(/32) in allowed IP list, it now works through the load balancer as well. So, NetBox/Django parses the first IP address from the
X-Real-IP
header and uses it when checking the allowed IP list.So, the question is: Do you see any problem in using
$proxy_add_x_forwarded_for
instead of$remote_addr
by default?Another question naturally is if something similar exists for Apache as well.
Beta Was this translation helpful? Give feedback.
All reactions