mirror of
https://github.com/NginxProxyManager/nginx-proxy-manager.git
synced 2026-04-25 09:25:55 +03:00
[GH-ISSUE #1762] Enable "network host mode" to get real client IP? #1311
Labels
No labels
awaiting feedback
bug
cannot reproduce
dns provider request
duplicate
enhancement
enhancement
enhancement
good first issue
help wanted
invalid
need more info
no certbot plugin available
product-support
pull-request
question
stale
troll
upstream issue
v2
v2
v2
v3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/nginx-proxy-manager-NginxProxyManager#1311
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @fdzaebel on GitHub (Jan 14, 2022).
Original GitHub issue: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/1762
Checklist
jc21/nginx-proxy-manager:latestdocker image?Describe the bug
My internal server does not get the real client IP. Via the "X-Forwarded-For" Header the internal server only gets the IP 172.19.0.1 which is the docker IP.
I tried to fix this problem by switching the docker network to "host" like explained in this solution: https://github.com/NginxProxyManager/nginx-proxy-manager/issues/41#issuecomment-464364484
This did not fix the problem but in my eyes this is the only way to handle that problem as it is related to docker and not to NPM.
But I think that the current release of NPM ignores or overwrites this network host configuration of the yaml file.
I think so because when I do an inspect of the docker container the network setting always look the same, no matter if I try this fix or not:
Could please anybody explain how I can start the current NPM docker version with network in host mode or maybe this is a new bug?
Nginx Proxy Manager Version
2.9.14
Operating System
Debian 10
@fdzaebel commented on GitHub (Jan 14, 2022):
I now fixed this problem. Here is my yaml code, so I removed all port configs:
I also have MariaDB running in docker. I had to change the yaml file for MariaDB also setting it no network mode "host" and then set the host-value for connecting to MariaDB to localhost (for me it was docker "db" before).
Now everything is working as expected.
@maxin-cn commented on GitHub (Dec 27, 2022):
@fdzaebel hi, I want to modify
npminto host mode, and I have installednpmin yourdocker-compose.yamlfile, but I cannot open the login interface of npm or log in to npm. Could you please tell me how to solve it? Thanks~@AmIBeingObtuse commented on GitHub (May 14, 2023):
I am also facing this issue with npm not loading admin interface or allowing proxy host connections also in the pursuit of real ip.
@neocult-de commented on GitHub (Jul 26, 2023):
I read this thread like 5 times and tried to research how to do it properly without breaking too much.
The
network_mode: hostworks for a correct "SourceIP"-Forwarding, but it breaks the principal of having other docker containers in an internal network, because host-mode and docker networks are mutually exclusive. That leads to the necessity of exposing the mysql-docker for NPM and any other service on the same host to be adressed differently and unnecessarily expose their ports to the host.The iptable-rule solution to masquerade packages is harder to do, might depend on server and deployment and is harder to maintain.
What worked for me is letting the docker container bind directly to the host port, so it doesn´t use the docker-proxy to be forwarded and thus changing the source IP. Adding 0.0.0.0 to the ports to bind on all Interfaces (Internal docker networks your NPM container is attached to AND the host port directly) --> Therefore directly getting the SourceIP on Port 80/443 (or another Stream Port if necessary), but keep the internal networking for database and other docker images fully functional.
To make that happen adopt the docker run command
-p 0.0.0.0:80:80 -p 0.0.0.0:443:443(Adding 0.0.0.0 to the port forwarding for the npm-docker image)For docker-compose
Worked for me on Port 80/443 to have the SourceIP
Edit: If you want IPv6 to work as well you have to extend the port configuration:
docker run
-p 0.0.0.0:80:80 -p 0.0.0.0:443:443 -p [::0]:80:80 -p [::0]:443:443docker compose
@AmIBeingObtuse commented on GitHub (Jul 26, 2023):
I'm running docker desktop on Windows 10 pro and the only single issue I have is I cannot get the source IP always the docker IP. Tried 0.0.0.0:80:80 and 0.0.0.0:443:443 and still dont work.
Ive tried so many guides out there. I long for the day I can get the real IP 😄
@neocult-de commented on GitHub (Jul 26, 2023):
Then it would seem that the notation the same as network-mode host only works on Linux for now
@0bo commented on GitHub (Aug 28, 2023):
Same here, cant login at port81, and didn't test it works to get the real ip.
@0bo commented on GitHub (Aug 28, 2023):
I tried this and also tried another compose type
neither works... tired... let it be then ...
@neocult-de commented on GitHub (Aug 28, 2023):
@0bo If you still want to give it a try, check the following steps first:
@0bo commented on GitHub (Sep 12, 2023):
@neocult-de Hi there:
Thank you. Now I am trying something else, they work fine.
@neocult-de commented on GitHub (Sep 12, 2023):
@0bo If you find an alternative, that's great.
For the "host mode and then not being able to login" issue:
If you are directly in host mode, connections between docker containers via the docker network do not work anymore, because all ports are directly bound on the host. Thus, nginx-proxy-manager container can't connect to its database-container anymore. There is no direct error message, but you will not be able to login with your credentials when they can not be verified with the database.
That is why I recommended to use the bind on all interface method (-p 0.0.0.0:80:80 -p 0.0.0.0:443:443) "instead of hostmode!". It will give the same result for nginx-proxy-manager directly handling requests, but still be able to use docker-network with other containers (important for database and if you want to reverse proxy other docker containers on the same host).
If you were able to activate host mode, then the bind on all interface method should work for you as well.
@0bo commented on GitHub (Sep 12, 2023):
@neocult-de
I fully understand the advantage of your suggestion, that's why I tried quite a few times.
But neither openwrt nor synology system does support this feature. I mean, when I apply the method like
-p 0.0.0.0:80:80 -p 0.0.0.0:443:443, by compose or just one line command, in some situations it may notifies wrong format, or sometimes it just works as normal bind method, no difference.I guess this may be due to the system itself, for example, in debian or ubuntu, it may work as you said, but not in my case.
@neocult-de commented on GitHub (Sep 12, 2023):
@0bo If the host mode works for you:
If the binding notation for all interfaces does not work for you, you might be able to set it specifically for your host ip and docker network in question. (I personally have done all for keeping the docker network connection to all my container and services)
Alternatively: Use host mode on database container as well - You can get access to the database theoretically by binding the database-container as well in host mode and connect locally to it (you might need to use the IP of the device and not a binding like localhost / 127.0.0.1 to connect from nginx-proxy-manager to the database)
(Not being able to use the all interfaces notation might be issues with interfaces and routing on OpenWrt and Synology (Plenty of reasons for these stations to have modifications in these area) OR an older version of docker as the Interface binding notation is a newer feature.
@Zammla commented on GitHub (Mar 11, 2024):
This worked for me on Linux! THANK YOU SO MUCH! Trying this for weeks and finally it worked.
@LiamKarlMitchell commented on GitHub (Aug 11, 2024):
On WSL2 Windows 10, can't do host network (once enabled in experimental features of docker desktop) and still have access to docker named networks that are marked external: true etc, to share between various containers to be able to access them by their host names.
Listening with the 0 bind address did not work in this case.
However, can possibly have two Nginx's or some other proxy.
One on host that reverse proxies to one that has different port exposed for http, to then be able to connect to docker bridge networks as well.
Nginx + Host Network enabled listens on 80,443 etc.
Reverse proxies all traffic? to port 83 for instance
The nginx running for container networks, can then handle them as needed.
Kind of a round about way to do it, if it works...
Would also let allowing only cloudflare ipv4 + lan + docker to access "public" sites as well due to the separation and having the real connecting ip... Although that can be allowed through firewall as well and probably should be but block other traffic etc.
@neocult-de commented on GitHub (Aug 12, 2024):
@LiamKarlMitchell The most outer reverse proxy does the SSL-Certificate and Handling for you on the publicly reachable end in almost any case, if you move that process to any other proxy inside you will run into managament overhead, certificate copying whatever. You would like to aim for that goal.
I run Nextcloud-AIO (All-in-one) behind Nginx Proxy Manager and the correct IP gets handled from NPM (Reverse Proxy) ->Caddy (Reverse Proxy) -> Apache (Webserver) and has the correct IP - Thats possible through the chain, but it doesn´t fix the original issue for you.
What you could try in WSL2 Windows 10 instead of outright host mode and instead of the all interface binding notation (-p 0.0.0.0:80:80 -p 0.0.0.0:443:443) you can try to notate your network IP and every docker network ip your npm-proxy-manager gets.
This would lead to the overhead of adding every ip your npm-proxy gets internally in docker assigned into your docker compose file, but it should give the chance for proper IP by listening on the actual network interface and the proper docker names through its docker interface at the same time.
HINT: Might need the experimental option activated - might not work on WSL properly
@LiamKarlMitchell commented on GitHub (Aug 12, 2024):
Update, Even host mode with experimental mode on windows 10 Wsl2 did not work unfortunately, well with pi hole which I tried host network on first rather than npm, could see a new "ip" for each client connection this time it was always localhost even though the device doing the dns query was my phone for instance not my pc.
So im confident nginx would be the same in host mode even with hosting two instances of it etc. Bummer.
@neocult-de commented on GitHub (Aug 12, 2024):
Try interface binding notation for
and try again.
e.g. for PiHole DNS Request try (with your actual ips!)
docker run
-p 0.0.0.0:53:53 -p 192.168.0.10:53:53 -p 172.20.0.5:53:53
docker compose
ports:
- '0.0.0.0:53:53'
- '192.168.0.10:53:53'
- '172.20.0.5:53:53'