Reverse proxy, downstream Real-IP Topic is solved

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
DomoticzCH
Posts: 6
Joined: Saturday 22 May 2021 7:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: CH
Contact:

Reverse proxy, downstream Real-IP

Post 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!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Reverse proxy, downstream Real-IP

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DomoticzCH
Posts: 6
Joined: Saturday 22 May 2021 7:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: CH
Contact:

Re: Reverse proxy, downstream Real-IP

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Reverse proxy, downstream Real-IP

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DomoticzCH
Posts: 6
Joined: Saturday 22 May 2021 7:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: CH
Contact:

Re: Reverse proxy, downstream Real-IP

Post 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 :)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Reverse proxy, downstream Real-IP

Post 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?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DomoticzCH
Posts: 6
Joined: Saturday 22 May 2021 7:47
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: CH
Contact:

Re: Reverse proxy, downstream Real-IP

Post 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" !
hestia
Posts: 361
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

Re: Reverse proxy, downstream Real-IP

Post by hestia »

Hi,
I did it like this with Synology
reverseProxy.png
reverseProxy.png (16.23 KiB) Viewed 1148 times
I think there is a typo in the wiki
X-Forwarded_Proto => X-Forwarded-Proto
User avatar
waltervl
Posts: 5851
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Reverse proxy, downstream Real-IP

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hestia
Posts: 361
Joined: Monday 25 December 2017 23:06
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Paris
Contact:

Re: Reverse proxy, downstream Real-IP

Post by hestia »

thanks :-)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest