1. The problem I’m having:
To simplify my problem as much as possible, let’s consider that I have 3 VMs: one with Caddy (proxy.domain.lan) and two Apache servers (selmai.domain.lan & web.domain.lan).
“proxy” is the entry point of all my web traffic (80 / 443).
If I receive a request on the domain “selmai.fr”, I want it to be directed to “selmai.domain.local”
If I receive a request on the domain “asso.ericdelcamp.fr”, I want it to be directed to “web.domain.local:3000” (there will eventually be several sites hosted on this VM with each a different port.
Everything works fine with “selmai.fr” but I recently built this VM.
When I try to reach “asso.ericdelcamp.fr”, I always end up on the default Apache page and not on the site.
- Does “proxy” need to have certificates for itself?
- To get a certificate for “asso.ericdelcamp.fr”, I use certbot locally by cutting the port forwarding to the proxy and by modifying my apache config, the time to get a certificate. Is this the right one method?
- Why can’t I get anything other than the default Apache page? In my address bar, the URL “asso.ericdelcamp.fr” is transformed into “web.domain.local”.
2. Error messages and/or full log output:
Jan 17 21:42:21 proxy systemd[1]: Reloading caddy.service - Caddy...
Jan 17 21:42:21 proxy caddy[1048]: {"level":"info","ts":1737146541.240933,"msg":"using config from file","file":"/etc/caddy/Caddyfile"}
Jan 17 21:42:21 proxy caddy[1048]: {"level":"info","ts":1737146541.2426274,"msg":"adapted config to JSON","adapter":"caddyfile"}
Jan 17 21:42:21 proxy systemd[1]: Reloaded caddy.service - Caddy.
3. Caddy version:
2.9.1
4. How I installed and ran Caddy:
a. System environment:
Ubuntu 24.04.1
Selmai : Apache/2.4.58 (Ubuntu)
Web : Apache/2.4.58 (Ubuntu)
b. Command:
curl -v http://selmai.fr
* Host selmai.fr:80 was resolved.
* IPv6: (none)
* IPv4: 82.65.33.149
* Trying 82.65.33.149:80...
* Connected to selmai.fr (82.65.33.149) port 80
> GET / HTTP/1.1
> Host: selmai.fr
> User-Agent: curl/8.9.1
> Accept: */*
>
< HTTP/1.1 308 Permanent Redirect
< Connection: close
< Location: https://selmai.fr/
< Server: Caddy
< Date: Fri, 17 Jan 2025 21:15:46 GMT
< Content-Length: 0
<
* we are done reading and this is set to close, stop send
* shutting down connection #0
curl -v http://asso.ericdelcamp.fr
* Host asso.ericdelcamp.fr:80 was resolved.
* IPv6: (none)
* IPv4: 82.65.33.149
* Trying 82.65.33.149:80...
* Connected to asso.ericdelcamp.fr (82.65.33.149) port 80
> GET / HTTP/1.1
> Host: asso.ericdelcamp.fr
> User-Agent: curl/8.9.1
> Accept: */*
>
< HTTP/1.1 308 Permanent Redirect
< Connection: close
< Location: https://asso.ericdelcamp.fr/
< Server: Caddy
< Date: Fri, 17 Jan 2025 21:16:28 GMT
< Content-Length: 0
<
* we are done reading and this is set to close, stop send
* shutting down connection #0
c. Service/unit/compose file:
d. My complete Caddy config:
{
debug
log default {
output file /var/log/caddy/caddy.log {
mode 600
}
}
}
selmai.fr {
reverse_proxy selmai.domain.lan {
header_up Host {upstream_hostport}
}
log {
output file /var/log/caddy/selmai.log
format transform `{request>headers>X-Forwarded-For>[0]:request>remote_ip} - {user_id} [{ts}] "{request>method} {request>uri} {request>proto}" {status} {size} "{request>headers>Referer>[0]}" "{request>headers>User-Agent>[0]}"` {
time_format "02/Jan/2006:15:04:05 -0700"
}
}
}
asso.ericdelcamp.fr {
reverse_proxy web.domain.lan:3000 {
header_up Host {upstream_hostport}
}
log {
output file /var/log/caddy/asso.log
format transform `{request>headers>X-Forwarded-For>[0]:request>remote_ip} - {user_id} [{ts}] "{request>method} {request>uri} {request>proto}" {status} {size} "{request>headers>Referer>[0]}" "{request>headers>User-Agent>[0]}"` {
time_format "02/Jan/2006:15:04:05 -0700"
}
}
}
e. Apache selmai.conf
<VirtualHost *:80>
ServerName selmai.fr
DocumentRoot /var/www/html
<Directory /var/www/html/phpbb>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/selmai_error.log
CustomLog ${APACHE_LOG_DIR}/selmai_access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =selmai.fr
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
f. Apache asso.conf
<VirtualHost *:3000>
ServerName asso.ericdelcamp.fr
DocumentRoot /var/www/dolibarr/htdocs/
ErrorLog ${APACHE_LOG_DIR}/dolibarr_error.log
CustomLog ${APACHE_LOG_DIR}/dolibarr_access.log combined
<Directory /var/www/dolibarr/htdocs/>
Require all granted
</Directory>
</VirtualHost>