1. The problem I’m having:
I am trying to make my multi-tenant app that requires ability to create subdomains with https on the fly - the main reason I’m using Caddy.
Right now, I have the main domain jatra.app running with Caddy; however, when I try to create a subdomain, I get the following error on browser:
# This page isn’t working
**community.jatra.app** is currently unable to handle this request.
HTTP ERROR 502
Note : I’ve added a CNAME record with my domain registrar as:
CNAME | * | jatra.app | 600
Not sure if this record is correct and required for serving subdomains with HTTPS.
2. Error messages and/or full log output:
{"level":"info","ts":1698040425.470538,"msg":"autosaved config (load with --resume flag)","file":"/var/lib/caddy/.config/caddy/autosave.json"}
{"level":"info","ts":1698040425.4708772,"logger":"admin.api","msg":"load complete"}
{"level":"info","ts":1698040425.4728577,"logger":"admin","msg":"stopped previous server","address":"localhost:2019"}
{"level":"error","ts":1698040457.6875722,"logger":"http.log.error","msg":"dial tcp 127.0.0.1:9000: connect: connection refused","request":{"remote_ip":"49.36.34.137","remote_port":"61999","client_ip":"49.36.34.137","proto":"HTTP/2.0","method":"GET","host":"community.jatra.app","uri":"/","headers":{"Cache-Control":["no-cache"],"Sec-Ch-Ua":["\"Chromium\";v=\"118\", \"Google Chrome\";v=\"118\", \"Not=A?Brand\";v=\"99\""],"Sec-Ch-Ua-Platform":["\"macOS\""],"Upgrade-Insecure-Requests":["1"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Accept-Encoding":["gzip, deflate, br"],"Sec-Fetch-Dest":["document"],"Accept-Language":["en-US,en;q=0.9,hi;q=0.8,la;q=0.7,mr;q=0.6"],"Sec-Ch-Ua-Mobile":["?0"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"],"Sec-Fetch-Site":["none"],"Sec-Fetch-Mode":["navigate"],"Sec-Fetch-User":["?1"],"Pragma":["no-cache"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"community.jatra.app"}},"duration":0.000406151,"status":502,"err_id":"azr0wki3g","err_trace":"reverseproxy.statusError (reverseproxy.go:1265)"}
{"level":"error","ts":1698040458.9116673,"logger":"http.log.error","msg":"dial tcp 127.0.0.1:9000: connect: connection refused","request":{"remote_ip":"34.254.53.125","remote_port":"36508","client_ip":"34.254.53.125","proto":"HTTP/1.1","method":"GET","host":"help.jatra.app","uri":"/","headers":{"User-Agent":["Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0"],"Accept-Encoding":["gzip, deflate"],"Accept":["*/*"],"Connection":["keep-alive"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"http/1.1","server_name":"help.jatra.app"}},"duration":0.000374922,"status":502,"err_id":"a8jw1ifpm","err_trace":"reverseproxy.statusError (reverseproxy.go:1265)"}
{"level":"error","ts":1698040459.5463603,"logger":"http.log.error","msg":"dial tcp 127.0.0.1:9000: connect: connection refused","request":{"remote_ip":"34.254.53.125","remote_port":"50135","client_ip":"34.254.53.125","proto":"HTTP/1.1","method":"GET","host":"help.jatra.app","uri":"/","headers":{"Connection":["keep-alive"],"User-Agent":["Mozilla/5.0 (X11; Linux x86_64; rv:83.0) Gecko/20100101 Firefox/83.0"],"Accept-Encoding":["gzip, deflate"],"Accept":["*/*"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"http/1.1","server_name":"help.jatra.app"}},"duration":0.000375224,"status":502,"err_id":"19akk333e","err_trace":"reverseproxy.statusError (reverseproxy.go:1265)"}
{"level":"info","ts":1698040582.5707989,"logger":"admin.api","msg":"received request","method":"POST","host":"localhost:2019","uri":"/load","remote_ip":"127.0.0.1","remote_port":"56458","headers":{"Accept-Encoding":["gzip"],"Content-Length":["1437"],"Content-Type":["application/json"],"Origin":["http://localhost:2019"],"User-Agent":["Go-http-client/1.1"]}}
{"level":"info","ts":1698040582.571156,"msg":"config is unchanged"}
{"level":"info","ts":1698040582.5711958,"logger":"admin.api","msg":"load complete"}
{"level":"error","ts":1698040605.8215187,"logger":"http.log.error","msg":"dial tcp 127.0.0.1:9000: connect: connection refused","request":{"remote_ip":"49.36.34.137","remote_port":"53019","client_ip":"49.36.34.137","proto":"HTTP/3.0","method":"GET","host":"community.jatra.app","uri":"/","headers":{"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"],"Sec-Fetch-Mode":["navigate"],"Sec-Fetch-Dest":["document"],"Sec-Ch-Ua-Mobile":["?0"],"Sec-Ch-Ua-Platform":["\"macOS\""],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Upgrade-Insecure-Requests":["1"],"Sec-Fetch-Site":["none"],"Accept-Language":["en-US,en;q=0.9,hi;q=0.8,la;q=0.7,mr;q=0.6"],"Sec-Ch-Ua":["\"Chromium\";v=\"118\", \"Google Chrome\";v=\"118\", \"Not=A?Brand\";v=\"99\""],"Sec-Fetch-User":["?1"],"Accept-Encoding":["gzip, deflate, br"]},"tls":{"resumed":true,"version":772,"cipher_suite":4865,"proto":"h3","server_name":"community.jatra.app"}},"duration":0.000566143,"status":502,"err_id":"h74mkd3qy","err_trace":"reverseproxy.statusError (reverseproxy.go:1265)"}
3. Caddy version:
v2.7.5 h1:HoysvZkLcN2xJExEepaFHK92Qgs7xAiCFydN5x5Hs6Q=
4. How I installed and ran Caddy:
Simply followed the instructions here: Install — Caddy Documentation
a. System environment:
uBuntu 22.04
b. Command:
NA
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:
{
on_demand_tls {
ask https://jatra.app/caddy/ask
interval 2m
burst 5
}
log {
output file /var/log/caddy/access.log {
roll_size 1gb
roll_keep 5
roll_keep_for 720h
}
}
}
https:// {
tls {
on_demand
}
reverse_proxy localhost:9000 # PHP-FPM listens on this port
}
# Sites block.
jatra.app {
root * /home/forge/jatra.app/public
php_fastcgi unix//run/php/php8.2-fpm.sock
file_server
}