sulu-builder: integrate nginx-mod-ws-auth for WebSocket authentication

Include ws-auth endpoints and fix nginx template updates to properly
  add WebSocket upgrade map and upstream directives independently.
This commit is contained in:
Sukru Senli 2026-01-17 00:17:11 +01:00 committed by Vivek Dutta
parent 8bda910d6a
commit df34679f38
2 changed files with 9 additions and 1 deletions

View file

@ -1,5 +1,8 @@
error_page 497 301 =307 https://$host:$server_port$request_uri;
# WebSocket authentication endpoints
include /etc/nginx/ws-auth-locations.conf;
location /robots.txt {
return 200 "User-agent: *\nDisallow: /\n";
}

View file

@ -20,8 +20,13 @@ update_nginx_uci_template()
port="$(uci -q get mosquitto.sulu.port)"
port="${port:-9009}"
if ! grep -w "upstream websocket" ${UCI_TEMPLATE} | grep -wq "127.0.0.1:${port}"; then
# Add map for WebSocket connection upgrade if not present
if ! grep -q "map \$http_upgrade \$connection_upgrade" ${UCI_TEMPLATE}; then
sed -i '/#UCI_HTTP_CONFIG$/i\ map $http_upgrade $connection_upgrade { default upgrade; "" close; }' ${UCI_TEMPLATE}
fi
# Add upstream websocket if not present
if ! grep -q "upstream websocket" ${UCI_TEMPLATE}; then
sed -i "/#UCI_HTTP_CONFIG$/i\ upstream websocket { server 127.0.0.1:${port}; }" ${UCI_TEMPLATE}
fi
}