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

48 lines
1.1 KiB
Plaintext
Raw Normal View History

#!/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;
}
EOT
fi
nginx: autoload dynamic modules In current setup, dynamic modules are not autoloaded, requiring users to create and load additional config files. We should assume that if a user installs additional modules, they want them 'on' by default. This commit does the following: 1.) generates a module load config in '/etc/nginx/modules.d' with the format '${module_name}'.module (i.e. /etc/nginx/modules.d/ngx_http_geoip2.module) 2.) deletes previous module conf for 'luci' /etc/nginx/modules.d/luci.module if it exists, this will prevent 'module already loaded' errors. The following is a portion of the final output when using the default uci template `/etc/nginx/uci.conf.template` (via nginx-util): ``` nginx -T -c '/etc/nginx/uci.conf' load_module /usr/lib/nginx/modules/ngx_http_brotli_filter_module.so; load_module /usr/lib/nginx/modules/ngx_http_brotli_static_module.so; load_module /usr/lib/nginx/modules/ngx_http_dav_ext_module.so; load_module /usr/lib/nginx/modules/ngx_http_geoip2_module.so; load_module /usr/lib/nginx/modules/ngx_http_headers_more_filter_module.so; load_module /usr/lib/nginx/modules/ngx_http_lua_module.so; load_module /usr/lib/nginx/modules/ngx_http_naxsi_module.so; load_module /usr/lib/nginx/modules/ngx_http_ts_module.so; load_module /usr/lib/nginx/modules/ngx_http_ubus_module.so; load_module /usr/lib/nginx/modules/ngx_rtmp_module.so; load_module /usr/lib/nginx/modules/ngx_stream_module.so; load_module /usr/lib/nginx/modules/ngx_stream_geoip2_module.so; ``` Signed-off-by: Sean Khan <datapronix@protonmail.com>
2024-04-13 00:05:30 +02:00
if [ ! -f "/etc/nginx/module.d/ngx_http_ubus.module" ]; then
cat <<EOT > /etc/nginx/module.d/ngx_http_ubus.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