1. The problem I’m having:
I’m trying to configure an ssl certificate for a webpage running behind caddy with certbot. I have configured caddy to redirect to 443 on the webpage server however certbot and browsers fail to access the webpage. As the webpage does not use SSL yet I don’t think caddy can forward to it, so I get an HTTP 502 error when I go to the domain I have configured. If I can’t access the webpage without an SSL cert, and to get an SSL cert I need to have access to the webpage, how do I proceed? Can someone guide me to the answer to the chicken and the egg?
Network setup is 443 is the only port open on the network which redirects to caddy, and caddy distributes depending on the domain name used (I have another server behind caddy that works fine (subdomain1) so i think caddy is fine and it is just certbot and caddy that clash)
2. Error messages and/or full log output:
i kept getting error 502 if i pasted it directly in here so here is a link
https://www.mediafire.com/file/7wk00ibjdpvlfik/log-redacted.txt/file
3. Caddy version:
v2.7.6 h1:w0NymbG2m9PcvKWsrXO6EEkY9Ru4FJK8uQbYcev1p3A=
4. How I installed and ran Caddy:
Installed using the Ubuntu packages
a. System environment:
Ubuntu 20.04.6 LTS, x86
b. Command:
caddy.service file
c. Service/unit/compose file:
# caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target
[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
d. My complete Caddy config:
# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.
{
debug # for the log file above only
}
subdomain1.domain.net {
reverse_proxy 192.168.2.5:8096
}
subdomain2.domain.net {
reverse_proxy 192.168.2.4:443
}.
Note that i have replaced the true domain names with subdomain 1 and 2, i have replaced them universally and i can not share the true domain names as their unknowingness is one line of security i have setup. subdomain1 works fine but subdomain2 is the one that doesnt work with certbot (im not saying subdomain1 works with certbot, im saying everything is fine with subdomain1)