Hello world not working on Caddyfile 2 - docker

1. My Caddy version (caddy version):

Caddy 2.0.0 (docker official image

2. How I run Caddy:

I followed the documentation

a. System environment:

docker under proxmox

b. Command:

$ docker run -d -p 80:80 -p 443:443
-v /site:/usr/share/caddy
-v caddy_data:/data
-v caddy_config:/config
caddy caddy file-server --domain mydomainDOTcom

c. Service/unit/compose file:

N/A

d. My complete Caddyfile or JSON config:

mydomainDOTcom

respond “Hello, world!”

3. The problem I’m having:

I am trying to install caddy 2 on docker

I set up caddy with this part of the documentation : Automatic TLS with the Caddy image

After running it when I type mydomainDOTcom on a web browser, https is correctly working.

I wanted to edit the Caddyfile as state on the doc. But in the docker command on the automatic TLS with caddy image, the path of the Caddyfile is not detailed.
I have tried to create it under /site:/usr/share/caddy, but it was not working (hello world was not displayed)

4. Error messages and/or full log output:

{“level”:“info”,“ts”:1588643323.458765,“logger”:“http”,“msg”:“server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS”,“server_name”:“static”,“https_port”:443}

{“level”:“info”,“ts”:1588643323.4587939,“logger”:“http”,“msg”:“enabling automatic HTTP->HTTPS redirects”,“server_name”:“static”}

{“level”:“info”,“ts”:1588643323.4594855,“logger”:“tls”,“msg”:“cleaned up storage units”}

{“level”:“info”,“ts”:1588643323.4599004,“logger”:“http”,“msg”:“enabling automatic TLS certificate management”,“domains”:[“mydomainDOTcom”]}

2020/05/05 01:48:43 [INFO][cache:0xc0003f8730] Started certificate maintenance routine

{“level”:“info”,“ts”:1588643323.6331892,“msg”:“autosaved config”,“file”:"/config/caddy/autosave.json"}

2020/05/05 01:48:43 Caddy 2 serving static files on :443

5. What I already tried:

Then I tried this

$ docker run -d -p 80:80 -p 443:443
-v /site:/usr/share/caddy
-v caddy_data:/data
-v caddy_config:/config
-v path to a folder/Caddyfile:/etc/caddy/Caddyfile
caddy caddy file-server --domain mydomainDOTcom

The Caddyfile with this inside :
mydomainDOTcom
respond “Hello, world!”

When I enter mydomainDOTcom, https is displayed but no hello world.

Question

Where do I need to put this Caddyfile under docker ? What are the permission of this file ? I have https working but caddy cannot access to the hello world of this Caddyfile.

Thank you

Whoa, there’s a lot of repeated information in your post. Did you accidentally paste the same sections more than once?

That said, the problem is that if you run Caddy with caddy file-server, you’re telling Caddy to ignore the Caddyfile config.

Instead, you should either use the default entrypoint by omitting caddy file-server --domain mydomainDOTcom from your docker command, or specifying the config file yourself by running it with caddy run --config /etc/caddy/Caddyfile.

2 Likes

Sorry for that mess with all duplicate content. I clean my original post.
I’ll try your suggestion ! Thank you

1 Like

You have told Caddy to ignore any Caddyfile and instead serve static files from the working directory Caddy is executed in. See:

Therefore, as it is not reading your Caddyfile, it does not take into account the respond directive you have specified in that Caddyfile.

1 Like

Great thank you for your help ! The documentation on docker caddy 2 is not very clear as default.
I ran this instead
$ docker run -d -p 80:80 -p 443:443
-v /site:/usr/share/caddy
-v caddy_data:/data
-v caddy_config:/config
caddy

Thanks for that tidbit. That confused me with example at The Caddyfile — Caddy Documentation listing file_server in Caddyfile but I couldn’t get the Caddy server to serve any files in Caddyfile root directive path. Removing file_server from Caddyfile fixed it but why is the example at The Caddyfile — Caddy Documentation set out that way with file_server directive inside ?

example.com

root * /path/to/public_html
try_files {path} /index.php?{query}&p={path}
php_fastcgi unix//run/php/php-fpm.sock
file_server

remove try_files, php_fastcgi already passing try_files for you.

oh sorry didn’t mention my example used

example.com

root * /path/to/public_html
php_fastcgi 127.0.0.1:9000
file_server

removing file_server fixed serving my public_html/index.html file

I’m confused @eva2000, could you expand on what you’re saying? That doesn’t make sense to me. Maybe open a new thread and fill out the template so we have a good idea of what’s going on?

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