About caddy setup

Hello.
I’m planning to move from Apache to Caddy.
However, there are some things I don’t understand, so I would appreciate any advice.
Details are described below.

1. Caddy version (caddy version):

v2.2.1 h1:Q62GWHMtztnvyRU+KPOpw6fNfeCD3SkwH7SfT1Tgt2c=

2. How I run Caddy:

I have caddy installed with apt and running with systemctl.

a. System environment:

KVM VPS
Ubuntu 20.04.1

b. Command:

paste command here

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:

I set the following contents in “/etc/caddy/caddyfile”.

https://riku22.me{
	tls /etc/caddy/certs/riku22.me/fullchain.pem /etc/caddy/certs/riku22.me/privkey.pem
	file_server
	root * /home/riku/public_html/riku22.me
	php_fastcgi unix//run/php/php7.4-fpm-riku.sock
}

3. The problem I’m having:

After restarting caddy with “systemctl restart caddy”, I accessed “https://riku22.me”, but I only see an empty page and no content.
By the way, the following contents are set as “/home/riku/public_html/riku22.me/index.html”.

Test server.

For files and directories in “/home/riku/public_html/riku22.me/”, “riku” is set as the user and “riku” is set as the group.

4. Error messages and/or full log output:

I’m sorry, I didn’t know how to get the log.
I will check it a bit more.

5. What I already tried:

6. Links to relevant resources:

Hello.

I was able to get the log, so I will describe it below.

Oct 29 22:02:50 sv01 systemd[1]: Started Caddy.
Oct 29 22:02:50 sv01 caddy[21215]: caddy.HomeDir=/var/lib/caddy
Oct 29 22:02:50 sv01 caddy[21215]: caddy.AppDataDir=/var/lib/caddy/.local/share/caddy
Oct 29 22:02:50 sv01 caddy[21215]: caddy.AppConfigDir=/var/lib/caddy/.config/caddy
Oct 29 22:02:50 sv01 caddy[21215]: caddy.ConfigAutosavePath=/var/lib/caddy/.config/caddy/autosave.json
Oct 29 22:02:50 sv01 caddy[21215]: caddy.Version=v2.2.1
Oct 29 22:02:50 sv01 caddy[21215]: runtime.GOOS=linux
Oct 29 22:02:50 sv01 caddy[21215]: runtime.GOARCH=amd64
Oct 29 22:02:50 sv01 caddy[21215]: runtime.Compiler=gc
Oct 29 22:02:50 sv01 caddy[21215]: runtime.NumCPU=4
Oct 29 22:02:50 sv01 caddy[21215]: runtime.GOMAXPROCS=4
Oct 29 22:02:50 sv01 caddy[21215]: runtime.Version=go1.15.2
Oct 29 22:02:50 sv01 caddy[21215]: os.Getwd=/
Oct 29 22:02:50 sv01 caddy[21215]: LANG=ja_JP.UTF8
Oct 29 22:02:50 sv01 caddy[21215]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
Oct 29 22:02:50 sv01 caddy[21215]: HOME=/var/lib/caddy
Oct 29 22:02:50 sv01 caddy[21215]: LOGNAME=caddy
Oct 29 22:02:50 sv01 caddy[21215]: USER=caddy
Oct 29 22:02:50 sv01 caddy[21215]: INVOCATION_ID=473da4015af44ad2b1003f61616e5912
Oct 29 22:02:50 sv01 caddy[21215]: JOURNAL_STREAM=9:340637
Oct 29 22:02:50 sv01 caddy[21215]: {"level":"info","ts":1603976570.760716,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":""}
Oct 29 22:02:50 sv01 caddy[21215]: {"level":"info","ts":1603976570.7630746,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["localhost:2019","[::1]:2019","127.0.0.1:2019"]}
Oct 29 22:02:50 sv01 caddy[21215]: {"level":"info","ts":1603976570.763887,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc000277260"}
Oct 29 22:02:50 sv01 caddy[21215]: {"level":"info","ts":1603976570.765915,"logger":"http","msg":"enabling automatic HTTP->HTTPS redirects","server_name":"srv0"}
Oct 29 22:02:50 sv01 caddy[21215]: {"level":"info","ts":1603976570.7672238,"msg":"autosaved config","file":"/var/lib/caddy/.config/caddy/autosave.json"}
Oct 29 22:02:50 sv01 caddy[21215]: {"level":"info","ts":1603976570.767244,"msg":"serving initial configuration"}
Oct 29 22:02:50 sv01 caddy[21215]: {"level":"info","ts":1603976570.7679405,"logger":"tls","msg":"cleaned up storage units"}
Oct 29 22:02:57 sv01 caddy[21215]: {"level":"info","ts":1603976577.3398793,"logger":"http.log.access","msg":"handled request","request":{"remote_addr":"126.xxx.yyy.zzz:5516","proto":"HTTP/2.0","method":"GET","host":"riku22.me","uri":"/","headers":{"Te":["trailers"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"],"Accept-Language":["ja"],"Accept-Encoding":["gzip, deflate, br"],"Upgrade-Insecure-Requests":["1"],"Pragma":["no-cache"],"Cache-Control":["no-cache"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"riku22.me"}},"common_log":"126.xxx.yyy.zzz - - [29/Oct/2020:22:02:57 +0900] \"GET / HTTP/2.0\" 0 0","duration":0.000007163,"size":0,"status":0,"resp_headers":{"Server":["Caddy"]}}
Oct 29 22:02:57 sv01 caddy[21215]: {"level":"info","ts":1603976577.4921696,"logger":"http.log.access","msg":"handled request","request":{"remote_addr":"126.xxx.yyy.zzz:5516","proto":"HTTP/2.0","method":"GET","host":"riku22.me","uri":"/favicon.ico","headers":{"Pragma":["no-cache"],"Cache-Control":["no-cache"],"Te":["trailers"],"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:82.0) Gecko/20100101 Firefox/82.0"],"Accept":["image/webp,*/*"],"Accept-Language":["ja"],"Accept-Encoding":["gzip, deflate, br"],"Referer":["https://riku22.me/"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","proto_mutual":true,"server_name":"riku22.me"}},"common_log":"126.xxx.yyy.zzz - - [29/Oct/2020:22:02:57 +0900] \"GET /favicon.ico HTTP/2.0\" 0 0","duration":0.000007013,"size":0,"status":0,"resp_headers":{"Server":["Caddy"]}}

I think the problem is you’re missing a space before the { on your first line of your Caddyfile. Whitespace is significant in Caddy.

Basically you told Caddy your domain is riku22.me{ so when the request has riku22.me, Caddy doesn’t match that, so you get the default behaviour of an empty 200 response (which essentially means Caddy is running as expected but wasn’t configured to handle this request, so it’s not an error, but it had nothing to do).

1 Like

Hello.

I see.
It worked fine.
Thank you.

Best regards.

1 Like

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