The original post: /r/nginx by /u/lgr1206 on 2024-04-25 02:30:05.

Hi people!

My goal is to run NGINX as a proxy to PiHole and another applications behind NGINX proxy, and, use it to solve subdomains in LAN. So, I expect to be able to access this applications from any device inside my LAN.

To achiave this I’ve pointed all devices in my LAN to use PiHole DNS and I’ve registered in PiHole DNS solver table two subdomains pihole.localhost and app2.localhost, both pointing to my server LAN IP (192.168.18.187).

Everything works if I directly use the 192.168.18.187 IP, I can reach the PiHole dashboard as it’s my default application in NGINX. But if I try pihole.localhost, it throws the error ERR_CONNECTION_REFUSED.

Here are my all docker compose files:

  • nginx-proxy docker-compose file:
version: '3.3'
services:
  nginx-proxy:
    image: nginxproxy/nginx-proxy:alpine
    restart: always
    ports:
      - "80:80"
    environment:
      DEFAULT_HOST: pihole.localhost
    volumes:
      - ./current/public:/usr/share/nginx/html
      - ./vhost:/etc/nginx/vhost.d
      - /var/run/docker.sock:/tmp/docker.sock:ro
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
networks:
  default:
    external:
      name: nginx-proxy

  • PiHole docker-compose file:
version: "3.3"

# https://github.com/pi-hole/docker-pi-hole/blob/master/README.md

services:
  pihole:
    image: pihole/pihole:latest
    ports:
      - '53:53/tcp'
      - '53:53/udp'
      - "67:67/udp"
      - '8053:80/tcp'
    volumes:
      - './etc-pihole:/etc/pihole'
      - './etc-dnsmasq.d:/etc/dnsmasq.d'
    environment:
      FTLCONF_LOCAL_IPV4: 192.168.18.187
      #PROXY_LOCATION: pihole
      PROXY_LOCATION: 192.168.18.187:80
      VIRTUAL_HOST: pihole.localhost
      VIRTUAL_PORT: 80
    networks:
      - nginx-proxy
    restart: always

networks:
  nginx-proxy:
    external: true

And I’ve checked if the pi-hole DNS solving was correct, and it’s working properly:

> nslookup pihole.localhost
Server:192.168.18.187
Address:192.168.18.187#53

Name:pihole.localhost
Address: 192.168.18.187

If I try to access my applications inside my server where everthing is running I can access then perfectly. So I’ve checked that my applications are working as well.

I don’t understand why the DNS is solving the correct IP and I’m still receiving ERR_CONNECTION_REFUSED.

Thanks in advance!