1. The problem I’m having:
Hello,
Context :
I’m trying to configure a host to serve a nextjs app. In order to avoid any downtime when publishing, I have setup a “blue-green” deployment following this post
Ofc, I don’t use nginx but Caddy so I’m trying to make the configuration for Caddy.
TL;DR, I have two nextjs running through pm2, one on port 3000 and the other one on port 3001.
Only one is running at a time.
The result is a 502 error.
The configuration works if I only have the running nextjs as the reverse_proxy
2. Error messages and/or full log output:
{"level":"error","ts":1732899944.9000401,"logger":"http.log.error.log0","msg":"dial tcp 127.0.0.1:3001: connect: connection refused","request":{"remote_ip":"80.201.38.152","remote_port":"60471","client_ip":"80.201.38.152","proto":"HTTP/1.1","method":"GET","host":"myhub.inowai.com","uri":"/","headers":{"User-Agent":["curl/8.9.1"],"Accept":["*/*"]},"tls":{"resumed":false,"version":771,"cipher_suite":49195,"proto":"http/1.1","server_name":"myhub.inowai.com"}},"duration":0.006365153,"status":502,"err_id":"8cqe2r7z9","err_trace":"reverseproxy.statusError (reverseproxy.go:1269)"}
3. Caddy version:
v2.8.4
4. How I installed and ran Caddy:
Using the stable release doc on Install — Caddy Documentation
a. System environment:
Ubuntu 22.04.4
b. Command:
sudo systemctl (re)start|stop 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:
(common) {
# security stuff
header /* {
-Server
X-Content-Type-Options nosniff
X-Frame-Options DENY
Strict-Transport-Security max-age=31536000;
}
}
myhub.inowai.com {
import common
encode gzip zstd
# Storage path for files
root * /mnt/aiweb
@exists file
handle @exists {
file_server
}
reverse_proxy localhost:3000 localhost:3001
file_server
log {
output file /var/log/caddy/inowai.log {
roll_keep 8
roll_keep_for 72h
}
format json
}
tls backend@opp.mx
}