Caddy running in background, site not visible via curl or browser

1. The problem I’m having:

I’m trying to use Caddy to serve my site on Digital Ocean. I followed a recent tutorial (see below for link) but when I check the web browser it says site cannot be found.

One issue that came up during the tutorial was with this command: sudo systemctl start caddy When I run it, I get

**Job for caddy.service failed because the control process exited with error code.**

**See "systemctl status caddy.service" and "journalctl -xeu caddy.service" for details.**

When I do sudo caddy start it does say Caddy is running in a background process. but when I

curl https://localhost:443

I get

curl: (35) OpenSSL/3.0.10: error:0A000438:SSL routines::tlsv1 alert internal error

2. Error messages and/or full log output:

**Job for caddy.service failed because the control process exited with error code.**

**See "systemctl status caddy.service" and "journalctl -xeu caddy.service" for details.**


curl: (35) OpenSSL/3.0.10: error:0A000438:SSL routines::tlsv1 alert internal error

3. Caddy version:

v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=

4. How I installed and ran Caddy:

sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf ‘https://dl.cloudsmith.io/public/caddy/stable/gpg.key’ | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf ‘https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt’ | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

a. System environment:

  • Ubuntu 23.10 x64

b. Command:

sudo caddy start

sudo systemctl start caddy

c. Service/unit/compose file:

PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.

d. My complete Caddy config:

cabincrewforyou.com {
	root * /var/www/html/public

	file_server
}

5. Links to relevant resources:

This is the tutorial I followed to serve my Hugo blog with Caddy

You should never use sudo caddy start if you have Caddy installed to run as a systemd service.

Follow the instructions at Keep Caddy Running — Caddy Documentation to use it correctly.

You’ll probably need to run sudo caddy stop to make sure no Caddy instance is still running, before starting up the systemd service again.

Hi, I followed the instructions at the webpage (thank you). It turns out I didn’t have the /etc/systemd/system/caddy.service file, nor the Caddyfile in the proper location /etc/caddy/Caddyfile . However, now that I follow the proper instructions, I get this error, when I do systemctl status caddy

× caddy.service - Caddy
Loaded: loaded (/etc/systemd/system/caddy.service; enabled; preset: enabled)
Active: failed (Result: exit-code) since Sat 2024-02-10 12:29:55 UTC; 2min 12s ago
Duration: 4min 3.200s
Docs: Welcome — Caddy Documentation
Process: 25321 ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile (code=exited, status=1/FAI>
Main PID: 25321 (code=exited, status=1/FAILURE)
CPU: 72ms

This is my Caddyfile. I’m not sure if it’s relevant

cabincrewforyou.com {

Set this path to your site’s directory.

root * /var/www/html/public

Enable the static file server.

file_server

Another common task is to set up a reverse proxy:

reverse_proxy localhost:8080

Or serve a PHP site through php-fpm:

php_fastcgi localhost:9000

}
{
servers {
metrics
}
}

Please use code blocks, not quotes, when sharing your config and logs. It’s extremely difficult to read as-is.

Code blocks start and end with ``` on their own lines. Or click the </> button.

There’s no error message there. Please follow the instructions in the docs for showing your Caddy logs.

I apologize for the bad formatting, but there was an error there. Do you see the word “failed” in the output below, which I get from running

systemctl status caddy

.

× caddy.service - Caddy
Loaded: loaded (/etc/systemd/system/caddy.service; enabled; preset: enabled)
Active: failed (Result: exit-code) since Sat 2024-02-10 12:29:55 UTC; 2min 12s ago
Duration: 4min 3.200s
Docs: Welcome — Caddy Documentation
Process: 25321 ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile (code=exited, status=1/FAI>
Main PID: 25321 (code=exited, status=1/FAILURE)
CPU: 72ms

“Failed” is not logs, and it’s not an error message. It’s a status code. It’s just systemd saying “the program didn’t start successfully”.

We need to see the logs (with journalctl) to know what actually happened and why Caddy failed to start.

Again, see Keep Caddy Running — Caddy Documentation, it has the command you should run to see your logs.

Salut,
Thank you for clarifying the difference between the error and status code.

There’s no entries in the journal log. I had actually already looked at the page you referred to and ran this command

journalctl -u caddy --no-pager | less +G

but I didn’t mention it because there are no entries in it.

Any ideas? Thank you for your help.

Your Caddy installation might be messed up.

Try reinstalling Caddy with sudo apt remove caddy && sudo apt install caddy.

Thank you for the suggestion. I did exactly as you requested, but the problem is the same. I checked the journal logs again and they are empty.

Job for caddy.service failed because the control process exited with error code.
See "systemctl status caddy.service" and "journalctl -xeu caddy.service" for details.
mike@ubuntu-s-1vcpu-1gb-nyc3-01:/$ journalctl -u caddy --no-pager | less +G
mike@ubuntu-s-1vcpu-1gb-nyc3-01:/$ systemctl status caddy.service
× caddy.service - Caddy
     Loaded: loaded (/etc/systemd/system/caddy.service; enabled; preset: enabled)
     Active: failed (Result: exit-code) since Sat 2024-02-10 15:12:19 UTC; 34s ago
   Duration: 4min 3.200s
       Docs: https://caddyserver.com/docs/
    Process: 27515 ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile (code=exited, status=1/FAI>
   Main PID: 27515 (code=exited, status=1/FAILURE)
        CPU: 81ms

You seem to be using DigitalOcean. There’s an issue that causes logs to not be found. Read the answer here for explanation and fix for the logs finding issue. Once you resolve the DO issue, you’ll see the log messages we need to know.

I removed /var/lib/dbus/machine-id and etc/machine-id as it said in that serverfault.com answer. I then did systemctl status caddy and got the same failed status. I checked the journal files journalctl -u caddy --no-pager | less +G and it said there were no entries.

If the journal logs are actually not being found rather than empty, where can they be if the location is determined by the machine-id, which I no longer have?

cat /var/lib/dbus/machine-id 
cat: /var/lib/dbus/machine-id: No such file or directory

the answer on serverfault.com you referred me to told me to remove the machine-id files, it didn’t tell me to do anything more, so I don’t know where these journal logs are?

alternatively, is it possible the journal log is really just empty?

The only way it would be is if Caddy crashed instantly because of somekind of kernel/architecture type problem, I think. You would see something otherwise.

I dunno, @Mohammed90 knows more about DigitalOcean than I do but I’ve heard a lot of strange behaviour with their VPSes.

You should reboot the machine after removing the files.

Nope. There’s always something logged. Reboot then check again.

1 Like

@francislavoie I haven’t resolved my issue with Digital Ocean (Caddy not working, can’t read the logs).

Do you know another VPS provider I might try where you haven’t heard strange things about their VPSes?

If you restart the server/droplet, it’ll have the logs.

Actually I did shutdown the droplet and reboot it and it has created even more problems, and I still don’t have the logs and caddy isn’t working.and I contacted Digital Ocean support about it and they said caddy is third party software.

That’s why I’m looking for a new place to host my blog with caddy. Can you or @francislavoie recommend another vps provider? Francis said he had heard bad things about DO droplets and I believe him so I assume he might know other cow providers where there are no issues hosting caddy.

Thank you both for your help

:man_shrugging:

You could try Linode, or AWS EC2 (Amazon).

There’s tons of available options.

The trouble I’ve seen with DO is that they heavily customize their stock Linux images, and those customizations often break assumptions that most users make.

I can confirm for anyone running into the same problem that Caddy became considerably easier to use after switching from Digital Ocean. I was never able to find the logs on DO, and after shutting down my droplet, it wouldn’t restart until I went through a lengthy process of running various scripts. Once the droplet was running again, I had to install a new package with apt but once I did that caddy went down again, and, as before, the journal logs were empty. None of this happened on my new VPN provider. This is not in anyway meant to slag Digital Ocean. They have been very good to me in the past and their support team was very helpful. It just seems that the way they set up their VPNs is a bad fit for Caddy.

Hmm… I would love to know step by step what you did after logging into the server for the first time, to see if we can identify why you are having those troubles. If you happen to start over again, feel free to paste your command log/history here. :slight_smile:

The first thing I did was follow this Digital Ocean tutorial for setting up a firewall.

After setting up the firewall on Digital Ocean, I installed Go lang and built Caddy from source using this tutorial https://www.digitalocean.com/community/tutorials/how-to-host-a-website-with-caddy-on-ubuntu-22-04. Then I deleted it once the tutorial required me to rebuild caddy to add the TLS plugin. Then I installed caddy with apt as described on the caddy website for ubuntu. At that point I was confused about systemctl’s purpose, as I tried to start caddy manually.
Things got very confused at that point, so I created a new droplet and installed caddy as described on the caddy website. At that point, everything from this link should tell you the rest. https://caddy.community/t/caddy-running-in-background-site-not-visible-via-curl-or-browser/22672/9