1. The problem I’m having:
I have a caddyfile ok with basic auth on https requests for port 12345.
now I have a service running websocket on port 23456, how to add it into the caddyfile?
2. Error messages and/or full log output:
3. Caddy version:
v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=
4. How I installed and ran Caddy:
a. System environment:
Ubuntu22.04
b. Command:
sudo caddy fmt Caddyfile --overwrite
sudo caddy reload Caddyfile
c. Service/unit/compose file:
d. My complete Caddy config:
The original caddyfile that works:
this_is_the_doman_name.xyz {
basicauth {
admin secret
}
reverse_proxy 127.0.0.1:12345
handle_errors {
respond "{http.error.status_code} {http.error.status_text}"
}
# Log startup messages
log {
output file /var/log/caddy/vitalik.log
format json
}
}
Now I modify it to
this_is_the_doman_name.xyz {
@port12345 {
host this_is_the_doman_name.xyz
header Host ":12345"
}
route @port12345 {
basicauth {
admin1 secret
}
reverse_proxy 127.0.0.1:12345
}
# Route for WebSocket requests on port 23456
@port23456 {
host this_is_the_doman_name.xyz
header Host ":23456"
}
route @port23456 {
basicauth {
admin2 secret
}
reverse_proxy 127.0.0.1:23456
}
handle_errors {
respond "{http.error.status_code} {http.error.status_text}"
}
# Log startup messages
log {
output file /var/log/caddy/vitalik.log
format json
}
}
Now both routes not responding.