Page 1 of 1

Reverse proxy, downstream Real-IP

Posted: Wednesday 26 May 2021 11:18
by DomoticzCH
hi all,

TLDR: request to implement logging of X-Real-IP

I am running Domoticz behind a NGINX reverse proxy with public IP access to connect from the Internet. Unfortunately, I don't see the X-Real-IP (or X-Forwarded-for header) from the downstream request (public IP) being passed to the upstream server (ie: Domoticz). In my Domoticz logs, I always see the IP address of my NGINX server (a private IP).

I realize that in the Domoticz settings you can set your reverse proxy IP address to require authentication, but this is not the problem here. I would really like to see in my logs from which downstream (Internet) IP address users are connecting from. Apart from an information point of view, this would also allow to setup fail2ban to mitigate brute force attacks.

So would it be possible to log the X-Real-IP header (if present) instead of the IP address? Should I request this on the GitHub page?

Thanks for your help!

Re: Reverse proxy, downstream Real-IP

Posted: Wednesday 26 May 2021 11:36
by waaren
DomoticzCH wrote: Wednesday 26 May 2021 11:18 So would it be possible to log the X-Real-IP header (if present) instead of the IP address? Should I request this on the GitHub page?
No but I moved this to the suggestions sub forum. If one of the developers is interested and want to spent time on it, she/he can create a Pull Request and after reviewing it could be integrated in a future version.

Re: Reverse proxy, downstream Real-IP

Posted: Wednesday 26 May 2021 16:16
by DomoticzCH
Thank you very much!

I think it's a fairly easy modification to the code (just check if X-Real-IP header is present and log that instead of "IP address"), and it would help everyone using a reverse proxy.

Re: Reverse proxy, downstream Real-IP

Posted: Wednesday 26 May 2021 16:47
by waaren
DomoticzCH wrote: Wednesday 26 May 2021 16:16 I think it's a fairly easy modification to the code (just check if X-Real-IP header is present and log that instead of "IP address")
Please feel free to create a PR for it.

Re: Reverse proxy, downstream Real-IP

Posted: Thursday 27 May 2021 8:35
by DomoticzCH
Duh, I must have overlooked something... When I put my proxy's IP address in the corresponding field, I now get the real IP addresses in the log! So everything is already perfect :)

Re: Reverse proxy, downstream Real-IP

Posted: Thursday 27 May 2021 9:15
by waaren
DomoticzCH wrote: Thursday 27 May 2021 8:35 Duh, I must have overlooked something... When I put my proxy's IP address in the corresponding field, I now get the real IP addresses in the log! So everything is already perfect :)
Can you please review this wiki page and advise if something needs more clarification?

Re: Reverse proxy, downstream Real-IP

Posted: Friday 28 May 2021 8:12
by DomoticzCH
No, that page is perfect, and if I would have read it until the end, I would have made less of a fool of myself :cry:
Especially the end which starts with "Please Note" !

Re: Reverse proxy, downstream Real-IP

Posted: Thursday 11 August 2022 18:41
by hestia
Hi,
I did it like this with Synology
reverseProxy.png
reverseProxy.png (16.23 KiB) Viewed 1151 times
I think there is a typo in the wiki
X-Forwarded_Proto => X-Forwarded-Proto

Re: Reverse proxy, downstream Real-IP

Posted: Friday 12 August 2022 9:26
by waltervl
hestia wrote: Thursday 11 August 2022 18:41 I think there is a typo in the wiki
X-Forwarded_Proto => X-Forwarded-Proto
Fixed, thanks for reporting.

Re: Reverse proxy, downstream Real-IP

Posted: Friday 12 August 2022 9:29
by hestia
thanks :-)