NginxProxyManager / nginx-proxy-manager

Docker container for managing Nginx proxy hosts with a simple, powerful interface
https://nginxproxymanager.com
MIT License
23.33k stars 2.7k forks source link

Host not working when using container's name with Podman #2197

Open matheusfenolio opened 2 years ago

matheusfenolio commented 2 years ago

Checklist

Describe the bug I'm trying to add a host using the name of the container, and when I open the URL, a 502 bad gateway appears. I tried using Docker, and it worked, but with Podman, it only works with container's IP.

Nginx Proxy Manager Version v2.9.18

To Reproduce Steps to reproduce the behavior:

  1. Create the container to forward: podman run --name web --network nginx-proxy-manager_default -d nginx:latest
  2. Add the host with: -Forward Hostname / IP: web -Port: 80
  3. Try to access service.

Expected behavior The Nginx welcome page should appear

Screenshots image

image

image

image

image

Operating System Tried on

Additional context docker-compose.yml version: '3' services: app: image: 'jc21/nginx-proxy-manager:latest' restart: unless-stopped ports:

the1ts commented 2 years ago

Don't think this is an NPM issue, there is lots of talk of podman issues around DNS after the default network change that was done for Podman 4 which was released in May of this year. Seems although CNI was left as the network stack if network was already setup, the DNS plugin was no longer used by default so this is the symptom. Try adding the DNS plugin to Podman for the old CNI network you probably have or remove the exisiting old network and upgrade to the new default network type which does have DNS builtin.

matheusfenolio commented 2 years ago

I'll give it a shot! I saw some issues about it, but I thought it was fixed since I'm able to connect two containers only using the container name.

BrandonG777 commented 1 year ago

whats strange is DNS works properly from command line, and even for creating subfolder proxies but not hostname proxies. hostnames will intermittently resolve which has me scratching my head even more.

BrandonG777 commented 1 year ago

Even using CNI network backend DNS is still intermittent. cannot replicate the issue at command line

the1ts commented 1 year ago

Sorry, I don't use podman or npm anymore, but there is a good reason why command line and nginx work differently. DNS for the command line is done via podman or whatever is setting up the container. Nginx is setup to use /data/nginx/resolv.conf. This from memory gets set at first start and perhaps is incorrect or has multiple servers in it, hence intermittent.

BrandonG777 commented 1 year ago

Well thanks for the reply anyway, you ultimately pointed me in the right direction. /data/nginx/resolv.conf no longer exist and didn't seem to have any affect on resolving this issue. However /etc/resolv.conf contained the podman host address and then my real host system dns entires. It appears that nginx was doing some sort of round robin selection of which DNS server it was going to use for lookup. Since this only affects host proxies and not subfolder location proxies I added a resolver entry to my host proxy custom config and that is working for me. I noticed the swag container uses 127.0.0.11 in it's resolver config which doesn't seem to work with this container. Maybe they are doing adding some sort of port forwarding or adding a package to make this work? Seems like that solution would work well for this container as well.

fuzzyfox commented 1 year ago

I believe I have tracked this down to a combination how nginx appears to handle the DNS resolution when it has multiple resolvers specified, and podman DNS resolution.

The issues can be resolved by manually altering the /etc/nginx/conf.d/include/resolvers.conf to only include the podman resolver ip, and no other ips. In my case:

# from
resolver 10.89.0.1 8.8.8.8 ipv6=off valid=10s;
# to
resolver 10.89.0.1 ipv6=off valid=10s;

This resolved my issues, obviously this wont stick through a container restart right now due to how this file is generated so as a more resilient interim solution I've added the updated resolvers line to the custom configs for proxies https://nginxproxymanager.com/advanced-config/#custom-nginx-configurations. Ideally I'd put it into the custom http.conf, however as nginx does not allow redeclaring directives, this wont work right now.

My proposal would be to allow a custom resolver config to be used on boot-up, and if it doesn't exist, then generate the file as it is right now.

github-actions[bot] commented 9 months ago

Issue is now considered stale. If you want to keep it open, please comment :+1:

patrickklaeren commented 3 months ago

I believe I have this exact error running Portainer and using the hostname, the exact same as in the original description above.