Caddy service can't start

1. Caddy version (caddy version):

v2.1.1 h1:X9k

2. How I run Caddy:

a. System environment:

Debian 9

b. Command:

sudo apt install caddy -y

d. My complete Caddyfile or JSON config:

domainname1.com {
 tls hb@domainname1.com
 reverse_proxy 127.0.0.1:3000 {
  header_up Host {http.request.host}
  header_up X-Real-IP {http.request.remote}
  header_up X-Forwarded-For {http.request.remote}
  header_up X-Forwarded-Port {http.request.port}
  header_up X-Forwarded-Proto {http.request.scheme}
 }
}

domainname2.com {
 tls hb@domainname1.com
 root /home/hb/website2
 file_server
}

3. The problem I’m having:

Caddy service can’t run. I have two websites on this server, one is visited through proxy, and another one is a static page (index.html).

4. Error messages and/or full log output:

● caddy.service - Caddy
   Loaded: loaded (/lib/systemd/system/caddy.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2020-11-10 08:25:08 UTC; 6s ago
     Docs: https://caddyserver.com/docs/
  Process: 8815 ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile (code=exited, status=1/FAILURE)
 Main PID: 8815 (code=exited, status=1/FAILURE)
      CPU: 38ms

Nov 10 08:25:08 ip-172-26-2-75 caddy[8815]: LANG=en_US.UTF-8
Nov 10 08:25:08 ip-172-26-2-75 caddy[8815]: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Nov 10 08:25:08 ip-172-26-2-75 caddy[8815]: HOME=/var/lib/caddy
Nov 10 08:25:08 ip-172-26-2-75 caddy[8815]: LOGNAME=caddy
Nov 10 08:25:08 ip-172-26-2-75 caddy[8815]: USER=caddy
Nov 10 08:25:08 ip-172-26-2-75 caddy[8815]: INVOCATION_ID=befe13c6c716403bbf3dd0ed648383b4
Nov 10 08:25:08 ip-172-26-2-75 caddy[8815]: JOURNAL_STREAM=8:138673
Nov 10 08:25:08 ip-172-26-2-75 systemd[1]: caddy.service: Main process exited, code=exited, status=1/FAILURE
Nov 10 08:25:08 ip-172-26-2-75 systemd[1]: caddy.service: Unit entered failed state.
Nov 10 08:25:08 ip-172-26-2-75 systemd[1]: caddy.service: Failed with result 'exit-code'.

5. What I already tried:

If I remove the domainname2.com’ configure section on Caddyfile, Caddy service can work well.

I’m pretty sure your problem is with root /home/hb/website2, you need to specify * as the request matcher here, because the next argument starts with / which Caddy instead guesses to be a request matcher.

Also, I’m almost certain you don’t need any of those header_up lines at all. Caddy already uses good defaults for those. Only add them if you actually know you need them.

Thank you for the reply, and I tried

domainname2.com {
 tls hb@domainname1.com
 root * /home/hb/website2
 file_server
}

But still the same issue.

Please run journalctl --no-page -u caddy | less (hit Shift+G to jump to the bottom), what do you see? Caddy should be reporting why it’s not starting.

I see, thank you so much.

:thinking:

What was the error then?

I missed file_server.

I’m confused, because you said you had file_server in your Caddyfile in earlier posts :thinking:

The process is like this. The first time I had file_server in Caddyfile and missed *, and then I modified the Caddyfile later, I forgot to add file_server. But in this post, I just copied the above code, so… sorry

1 Like

Ah okay :sweat_smile: thanks for explaining!

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