1. The problem I’m having:
I can’t make OpenHAB work correctly with Caddy as the reverse proxy. The OpenHAB sitemap itself loads fine, but something with websockets is just not working right: e.g. Firefox keeps throwing Firefox can’t establish a connection to the server at https://openhab.elektrik.link/rest/sitemaps/events/e289c7e0-f1ee-44e1-9516-abd1d44fcd84?sitemap=openhab&pageid=openhab.
in the console.
With NGINX it all appears to be working fine or at least I am not getting any errors either within Firefox or NGINX’s logs.
2. Error messages and/or full log output:
3. Caddy version:
v2.8.4 h1:q3pe0wpBj1OcHFZ3n/1nl4V4bxBrYoSoab7rL9BMYNk=
4. How I installed and ran Caddy:
Downloaded a binary.
a. System environment:
None of this seems relevant, since Caddy isn’t crashing or something.
d. My complete Caddy config:
{
email nita.vesa@outlook.com
acme_dns porkbun {
REDACTED
}
}
openhab.elektrik.link {
reverse_proxy * http://localhost:8080 {
transport http {
keepalive 1h
}
header_up Strict-Transport-Security max-age=31536000
header_up X-Real-IP {remote_host}
header_up X-Forwarded-Proto {scheme}
header_up Connection Upgrade
header_up Upgrade websocket
header_up Access-Control-Allow-Origin *
header_up Access-Control-Allow_Credentials true
header_up Access-Control-Allow-Headers Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range
header_up Access-Control-Allow-Methods GET,POST,OPTIONS,PUT,DELETE,PATCH
stream_timeout 24h
}
}
5. Links to relevant resources:
The NGINX config that appears to be working fine:
server {
listen 80;
server_name openhab.elektrik.link;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name openhab.elektrik.link;
# Cross-Origin Resource Sharing
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow_Credentials' 'true' always;
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' always;
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' always;
ssl_certificate /var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/openhab.elektrik.link/openhab.elektrik.link.crt;
ssl_certificate_key /var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/openhab.elektrik.link/openhab.elektrik.link.key;
add_header Strict-Transport-Security "max-age=31536000";
location / {
proxy_pass http://localhost:8080/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_read_timeout 3600;
}
}
Especially the proxy_read_timeout directive seems important as without it I’d get similar errors with NGINX. Alas, I cannot for the life of me find an equivalent in Caddy.