Solved: Cannot run Caddy as a systemd service


(Caddy Hello) #1

OS/Architecture: Raspbian Lite / Raspberry Pi Zero Wireless

Entering the command ‘caddy’ loads my localhost test site perfectly, but running it from systemd returns the error “404 Site 192.168.1.32:2015 is not served on this interface” in the browser and the following systemctl status log:

caddy.service - Caddy HTTP2 Web Server
   Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2017-09-07 22:31:58 EDT; 2min 27s ago
     Docs: https://caddyserver.com/docs
 Main PID: 433 (caddy)
   CGroup: /system.slice/caddy.service
           └─433 /usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile

systemd[1]: Started Caddy HTTP2 Web Server.
caddy[433]: Activating privacy features... done.
caddy[433]: http://localhost:2015
caddy[433]: 2017/09/07 22:31:59 http://localhost:2015
caddy[433]: 2017/09/07 22:34:04 [INFO] 192.168.1.32 - No such site at :2015 (Remote: 192.168.1.16, Referer: )

My /etc/systemd/system/caddy.service file is the following:

[Unit]
Description=Caddy HTTP2 Web Server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target networkmanager-wait-online.service

[Service]
Restart=on-failure
StartLimitInterval=86400
StartLimitBurst=5

User=www-data
Group=www-data

ExecStart=/usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile
ExecReload=/bin/kill -USR1 $MAINPID

LimitNOFILE=1048576
LimitNPROC=64

[Install]
WantedBy=multi-user.target

(Federico Bruni) #2

No such site at :2015

It seems that caddy cannot use this port? Or maybe failed to translate localhost to the right IP? (192.168.1.32 is a weird IP for localhost, usually it’s 127.0.0.1. Check your /etc/hosts file)

My guess (as a newbie) is that systemd is working fine and there’s something wrong in your Caddyfile or in your network configuration.

Are you sure you tested it with the same exact configuration you are using in systemd service?


(Matt Holt) #3

Close. :slight_smile: That error means that the Host in the reqeust didn’t match any host that Caddy was configured to serve on that port.


(Mark) #4

FYI, please don’t use the above unit file. Always check Caddy’s repository for an updated revision.


(Caddy Hello) #5

Hey folks, still having trouble. To address what you said:

  1. Using the Caddy unit file doesn’t work, that’s why I created my own, hoping to tweak it so it will work on my RPi.

  2. I’m pretty sure my Caddyfile isn’t the problem, it’s very simple:

localhost {
root /var/www/local
}


(Matthew Fay) #6

Maybe try this instead:

:2015 {
  root /var/www/local
}

Or access the site via localhost:2015 in the browser or via curl -H 'Host:localhost' 192.168.1.32:2015.


(Caddy Hello) #7

Here’s what finally worked:

localhost:2015 192.168.1.X:2015 {
    root /var/www/local
}

(system) #8

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