Caddy v2 cannot serve HTTPS

1. Caddy version (caddy version):

v2.1.1 h1:X9k1+ehZPYYRSqBvf/ocUgdLSRIuiNiMo7CvyGUQKeA=

2. How I run Caddy:

a. System environment:

Running in Docker.

b. Command:

Nothing fancy. A simple docker-compose up

c. Service/unit/compose file:

Here is my complete docker-compose.yml

version: '3'
services:
    caddy:
        image: caddy
        cap_add:
            - CAP_NET_BIND_SERVICE
        ports:
            - 80:80
            - 443:443
        volumes:
            - ./Caddyfile:/etc/Caddyfile
            - ./config:/config
            - ./data:/data

d. My complete Caddyfile or JSON config:

Here is my complete Caddyfile

mydomain.com
tls myemail@mydomain.com

3. The problem I’m having:

The log says that the “server is listening only on the HTTP port, so no dynamic HTTPS will be applied to this server”

4. Error messages and/or full log output:

Attaching to caddy_caddy_1
caddy_1  | {"level":"info","ts":1597710814.1092606,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
caddy_1  | {"level":"info","ts":1597710814.1145465,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["[::1]:2019","127.0.0.1:2019","localhost:2019"]}
caddy_1  | {"level":"info","ts":1597710814.1154902,"logger":"http","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
caddy_1  | {"level":"info","ts":1597710814.116081,"logger":"tls","msg":"cleaned up storage units"}
caddy_1  | {"level":"info","ts":1597710814.116735,"msg":"autosaved config","file":"/config/caddy/autosave.json"}
caddy_1  | {"level":"info","ts":1597710814.1171699,"msg":"serving initial configuration"}
caddy_1  | 2020/08/18 00:33:34 [INFO][cache:0xc000487800] Started certificate maintenance routine

5. What I already tried:

The same Caddyfile works well in a Caddy v1 based container. Going through the docs, this is supposed to work; but for the life of me, cannot figure out where I’m going wrong

1 Like

You didn’t use the correct location for the Caddyfile volume. By default, the config loaded is at /etc/caddy/Caddyfile. The logs you’re seeing are from the default Caddyfile which is shipped with the container, which only listens on :80.

Also, that config is definitely incomplete, You’ll need to add more directives for Caddy to do anything useful. In Caddy v1, a file server was always enabled by default, but in v2, it must be explicitly enabled with the file_server directive. You’ll want to set root as well to go along with this so Caddy knows where to read files from.

2 Likes

Welcome to the forum! Thank you for filling out the template. :slight_smile:

Thank You for not being too harsh. This is a classic RTFM moment for me.
I only needed to change the Docker mount to /etc/caddy/Caddyfile for it to work !

2 Likes

No worries! Not the most obvious mistake - I had to read your post over a couple times to notice.

Hope you have fun with Caddy!

:grin:

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