Not able to get response on https 127.0.0.1

1. The problem I’m having:

Hi, I’m trying to use https locally. When I access https://localhost, I get the expected html response, but when I try https://127.0.0.1, the browser gives error “This site can’t provide a secure connection”

3. Caddy version: v2.8.4

4. How I installed and ran Caddy:

a. System environment: docker on linux amd64

c. Service/unit/compose file:

services:
  caddy:
    image: caddy
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile

d. My complete Caddy config:

localhost, 127.0.0.1 {
        #tls internal Default behavior

        header Content-Type "text/html"
        respond "<h1> Welcome!</h1>" 200
}

When you run Caddy inside a container, 127.0.0.1 means “this same container”. Containers have their own network, like if it was another machine on your LAN. Requests will have your Docker gateway IP on them, not 127.0.0.1, so the Host header doesn’t match.

1 Like

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