packages/net/nginx/files-luci-support/60_nginx-luci-support

104 lines
No EOL
2.9 KiB
Bash

#!/bin/sh
if nginx -V 2>&1 | grep -q ubus && [ -f /usr/lib/nginx/modules/ngx_http_ubus_module.so ]; then
if [ -z "$(cat /etc/nginx/conf.d/luci.locations | grep ubus)" ]; then
cat <<EOT >> /etc/nginx/conf.d/luci.locations
location /ubus {
ubus_interpreter;
ubus_socket_path /var/run/ubus/ubus.sock;
ubus_parallel_req 2;
}
location ~ ^/ttyd(.*)$ {
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
proxy_set_header Connection "upgrade";
proxy_pass http://127.0.0.1:7681/\$1;
}
location ~ /netdata/(?<ndpath>.*) {
proxy_http_version 1.1;
proxy_pass http://127.0.0.1:19999/\$ndpath\$is_args\$args;
}
location /asterisk-ari/ {
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass https://127.0.0.1:6071/ari/;
proxy_set_header Authorization \$http_authorization;
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
}
location /asterisk-wss {
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass https://127.0.0.1:6071/ws;
proxy_set_header Authorization \$http_authorization;
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
}
location /aghome/ {
proxy_pass http://127.0.0.1:1887/;
proxy_redirect / /aghome/;
proxy_set_header Host \$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 X-Forwarded-Protocol \$scheme;
}
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$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;
}
EOT
fi
if [ ! -f "/etc/nginx/module.d/luci.module" ]; then
cat <<EOT >> /etc/nginx/module.d/luci.module
load_module /usr/lib/nginx/modules/ngx_http_ubus_module.so;
EOT
fi
fi
grep -q /var/run/ubus.sock /etc/nginx/conf.d/luci.locations &&
sed -i 's#/var/run/ubus.sock#/var/run/ubus/ubus.sock#' /etc/nginx/conf.d/luci.locations
if [ -x /etc/init.d/uhttpd ]; then
/etc/init.d/uhttpd disable
if [ -n "$(pgrep uhttpd)" ]; then
/etc/init.d/uhttpd stop
fi
fi
/etc/init.d/nginx enable
if [ -n "$(pgrep nginx)" ]; then
/etc/init.d/nginx restart
else
/etc/init.d/nginx start
fi
/etc/init.d/uwsgi enable
if [ -n "$(pgrep uwsgi)" ]; then
/etc/init.d/uwsgi restart
else
/etc/init.d/uwsgi start
fi
exit 0