1. The problem I’m having:
Switch to Caddy they said. It’ll be easy they said. Jokes aside, I’m having a lot of trouble switching from Apache to Caddy. Namely with global directives. I understand my use case is very non-traditional, which is why I’m here asking for help.
I have a lot of websites being served by Apache. A mixture of reverse proxies and local directories. In order to safely test out my configuration with Caddy, I’ve decided to run both Apache and Caddy simultaneously for the duration of the transition. Having both serve the same websites on different ports allows me to test both versions side by side in the browser.
Well Caddy doesn’t seem to like being told to listen on custom ports. I’ve seen other posts discussing this and they’re always advised against doing it, instead of being given an actual solution. And sure in some cases there might be better ways, but not in mine. And the HTTPS issue is easily countered with a DNS plugin - provided it’s configured correctly.
I couldn’t make the official installer page work with the plugins I chose, so I compiled it myself. But no mater what combination of directives I used I can’t get it to work.
As you can see, I also moved global headers into a separate file. Please let me know if there’s better ways to address any of these challenges.
2. Error messages and/or full log output:
Error: adapting config using caddyfile: server block without any key is global configuration, and if used, it must be first
3. Caddy version:
v2.8.1 h1:UVWB6J5f/GwHPyvdTrm0uM7YhfaWb4Ztdrp/z6ROHsM=
4. How I installed and ran Caddy:
Compiled with plugins.
a. System environment:
AlmaLinux 9, amd64, systemd.
b. Command:
systemctl start caddy
c. Service/unit/compose file:
[Unit]
Description=Caddy Web Server
Documentation=https://caddyserver.com/docs/
After=network.target
[Service]
User=apache
Group=apache
ExecStart=/etc/caddy/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
ExecReload=/etc/caddy/caddy run --config /etc/caddy/Caddyfile --adapter caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
[Install]
WantedBy=multi-user.target
d. My complete Caddy config:
{
debug
storage file_system /var/www/html
log default {
output file /var/log/caddy/caddy.log {
roll_keep_for 168h
}
include
level debug
format json
}
http_port 8888
https_port 4444
email [redacted]
acme_dns cloudflare [redacted]
}
import headers.caddy
//site blocks