NginxProxyManager / nginx-proxy-manager

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

Use Hostname instead of IP #2080

Open jpdore15 opened 2 years ago

jpdore15 commented 2 years ago

I have set up a couple of proxies without an issue using the IP of the service with the corresponding port, the issue I am running into is that when I try to use the hostname of the container I am getting a 502 error. When I use the IP address as the destination I can route to the correct service with the correct subdomain.domain.com combo

I have set up a custom docker bridge network and can ping the containers using the hostname and verify they are on the same network. I have also tried changing the site.conf file a couple of different ways to no avail.

I am currently using a QNAP 453 that has Portainer running, also I am very new to docker and the Linux environment.

This is the error I get when I have the destination Forward HostName/IP set to the containers Hostname:

[error] 426#426: *1541 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.254.254, server: (mydomain).com, request: "GET /favicon.ico HTTP/2.0", upstream: "http://192.168.100.2:7980/favicon.ico", host: "(mydomain).com", referrer: "(mydomain).com/"

This looks like its something to do with DNS not being able to travel from the local network to the container network. Any help would be appreciated.

Thank you

p10tyr commented 2 years ago

You have to remember that nginxman is running inside docker, private network with minimal setup.

It is likely that its not using your LAN dns (router, pfsense, or whatever) to query for local DNS's

I ran into the same thing. I use pfsense and have everything setup for local resolutions. Works on all my devices (Windows, Mac, Linux, IoT and Toaster) just fine!

I understand networking quite well but I am not super experienced with Docker networking and what would be required to allow the local nameserver for resolution.

Not figured that out yet. For now I can jsut assign static IP's to my various services and that works fine.. for now

keivanipchihagh commented 2 years ago

@jpdore15, Are your nginx-proxy-manager and other containers on the same network? You should add the following to the docker-compose files (you can change the name):

...
    networks:
      - nginx-proxy-manager

networks:
  nginx-proxy-manager:
    external: true

Also double check that they are actually on the same network with docker network inspect nginx-proxy-manager. Finally add the destination something like http://<service-name>:<port>.

Hope it helps!

github-actions[bot] commented 8 months ago

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

p10tyr commented 8 months ago

To follow up. I figured out that using the default network (eg, bridge) prevents internal name lookups. As suggested you need to create a new network, call it anything you like. Like internal and have it a bridge network. Make sure to add all your containers to this network (and remove bridge)

Now the containers will first use dockers internal mDNS to find another container by the name of the container or hostname provided, then start to go out to your networking DNS and then out to WAN