Reverse proxy *.localhost not working in Firefox or Chrome

1. Output of caddy version:

v2.6.2

2. How I run Caddy:

a. System environment:

docker

b. Command:

docker compose up -d

c. Service/unit/compose file:

version: "3.7"

services:
  caddy:
    image: caddy:latest
    container_name: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - /home/docker/caddy/Caddyfile:/etc/caddy/Caddyfile
      - /home/docker/caddy/site:/srv
networks:
  default:
    name: docker-net
    external: true

d. My complete Caddy config:

http://pihole.localhost {
        reverse_proxy pihole:80
}
http://portainer.localhost {
        reverse_proxy portainer:9000
}
http://router.localhost {
        reverse_proxy 10.0.1.1:80
}
http://wap.localhost {
        reverse_proxy 10.0.1.20:80 
}

3. The problem I’m having:

Everything works beautifully in Safari.

Firefox redirects to https://.

Chrome doesn’t redirect to https:// but still doesn’t work.

4. Error messages and/or full log output:

Firefox gives unable to connect

Chrome gives 'connection refused'

curl -v http://pihole.localhost
*   Trying 10.0.1.3:80...
* Connected to pihole.localhost (10.0.1.3) port 80 (#0)
> GET / HTTP/1.1
> Host: pihole.localhost
> User-Agent: curl/7.79.1
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 404 Not Found
< Content-Length: 0
< Content-Type: text/html; charset=UTF-8
< Date: Sun, 23 Oct 2022 07:00:16 GMT
< Server: Caddy
< Server: lighttpd/1.4.59
< 
* Connection #0 to host pihole.localhost left intact

5. What I already tried:

I’ve tried private mode in Firefox. Clearing history. Installing on a different machine and not signing into Firefox sync and without installing extensions.

6. Links to relevant resources:

Your system might not be configured to resolve *.localhost to 127.0.0.1 or ::1. Curl is reporting that it tries to connect to 10.0.1.3 instead.

That’s not really a problem with Caddy or your browsers, you’ll need to figure out how to configure your system such that it does.

Your system might not be configured to resolve *.localhost to 127.0.0.1 or ::1.

You’re right, but unless I’m missing something, how would that help? I ran that curl from a LAN device. It’s correctly forwarding it to the docker host at 10.0.1.3 where it hits caddy via port mapping. If http://pihole.localhost resolved to 127.0.0.1, it would never make it to caddy in the first place, no?

If you were trying to use that to connect to another device, then you’re using the wrong domain.

localhost and *.localhost are supposed to resolve to 127.0.0.1 or ::1, not to some other LAN IP address.

The “more correct” domain to use is .home.arpa for LAN use. You could use .local but that can cause issues because Apple devices use that for multicast.

1 Like

Ahh, that fixed the issue. I thought I had to use the .localhost domain.

Thanks!

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.