PiHole running behind nginx-proxy container is through connection refused

Hi people!
My goal is to run NGINX as a proxy and PiHole and another applications behind NGINX proxy. 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'
      # run `touch ./var-log/pihole.log` first unless you like errors
      # - './var-log/pihole.log:/var/log/pihole/pihole.log'
    # Recommended but not required (DHCP needs NET_ADMIN)
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    #cap_add:
    #  - NET_ADMIN
    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
    #extra_hosts:
      # Resolve to nothing domains (terminate connection)
      #- 'nw2master.bioware.com nwn2.master.gamespy.com:0.0.0.0'
      # LAN hostnames for other docker containers using nginx-proxy Ex:
      #- 'yourDomain.lan:192.168.41.55'
      #- 'pihole pihole.yourDomain.lan:192.168.41.55'
      #- 'ghost ghost.yourDomain.lan:192.168.41.55'
      #- 'wordpress wordpress.yourDomain.lan:192.168.41.55'
      #- 'pihole.localhost:192.168.18.187'
    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

Could anyone help me? Thanks in advance :pray:

I was following this tutorial:

What is the exact URL you are trying to access?

1 Like

This one:
http://pihole.localhost

But I've tried this another one as well:
http://app2.localhost

None of them has worked.
My apologies about the delay in responding. I wasn't notified about your reply.

Are you able to access the web interface directly, without the reverse proxy?

In your case, the URL should be http://192.168.18.187:8053/admin.

1 Like

Yes, I'm able to access the web interface directly as well using the 8053 port.

I'm having a similar issue and cannot figure it out!! I'm running this script I found in another forum post that helped out alot to get one of my instances connected fine. Just add it into the advanced block (credit goes to someone else, just sharing):

location / {
proxy_set_header Authorization "";
proxy_pass http://[Your IP]/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_hide_header X-Frame-Options;
proxy_set_header X-Frame-Options "SAMEORIGIN";
proxy_read_timeout 90;
}
location = / {
return 301 /admin;
}

This is working just fine on one instance, but I'm getting refused on my other and I'm not sure why.