Caddy not redirecting to HTTPS

1. Caddy version (caddy version):

latest

2. How I run Caddy:

a. System environment:

Docker

b. Command:

docker-compose up --build

c. Service/unit/compose file:

version: '3.7'
services:
  caddy:
    image: caddy:latest
    restart: unless-stopped
    ports:
      - 80:80
      - 443:443
      - 4000:4000
      - 8000:8000
      - 8080:8080
    volumes:
      - $PWD/Caddyfile:/etc/caddy/Caddyfile
      - $PWD/site:/srv
      - caddy_data:/data
      - caddy_config:/config

  postgres:
    image: postgres:12
    expose:
      - 5432
    restart: unless-stopped
    volumes:
      - skrrrt_data:/var/lib/postgresql/data
    env_file:
      - ./.env

  hasura:
    image: hasura/graphql-engine:v1.3.0
    expose:
      - 8080
    restart: unless-stopped
    depends_on:
      - postgres
    volumes:
      - ./hasura/migrations:/hasura-migrations
      - ./hasura/metadata:/hasura-metadata
    env_file:
      - ./.env

  app:
    build: ./
    expose:
      - 8000
    depends_on:
      - postgres
      - hasura
    restart: unless-stopped
    env_file:
      - ./.env

volumes:
  skrrrt_data:
  caddy_data:
  caddy_config:

d. My complete Caddyfile or JSON config:

skrrrt.io:80, skrrrt.io:443 {
  reverse_proxy * app:8000
}

skrrrt.io:8080 {
  reverse_proxy * hasura:8080
}

skrrrt.io:4000 {
  respond "reverse proxy working"
}

3. The problem I’m having:

When I access my website http://skrrrt.io I would expect to be redirected to HTTPS. HTTPS works, it’s just not redirecting to this.

I think the problem is you’ve explicitly told it to listen on 80, and not set a manual redirect.

This should work

   skrrrt.io {
      reverse_proxy * app:8000
    }

    skrrrt.io:8080 {
      reverse_proxy * hasura:8080
    }

    skrrrt.io:4000 {
      respond "reverse proxy working"
    }
3 Likes

That’s correct @caddy128.

The HTTP->HTTPS redirect is essentially implemented as a fallback handler for the server that’s listening on port 80. If you explicitly serve something on port 80, then you’ll override the redirect, because what you configured will be handled first.

1 Like

Worked great - thank you both so much for the quick responses!

1 Like

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