|
|
@@ -0,0 +1,110 @@
|
|
|
+#!/bin/bash
|
|
|
+# info: Adding fast cgi nginx support
|
|
|
+# options: USER DOMAIN [DEBUG]
|
|
|
+# labels: hestia web
|
|
|
+#
|
|
|
+# example: v-add-web-domain-fast-cgi-cache user domain.tld
|
|
|
+#
|
|
|
+# Function enables fast cgi support for Nginx
|
|
|
+# Add "yes" as last parameter append debug information to response headers
|
|
|
+
|
|
|
+
|
|
|
+#----------------------------------------------------------#
|
|
|
+# Variable&Function #
|
|
|
+#----------------------------------------------------------#
|
|
|
+
|
|
|
+# Argument definition
|
|
|
+user=$1
|
|
|
+domain=$2
|
|
|
+debug=$3
|
|
|
+
|
|
|
+# Includes
|
|
|
+source $HESTIA/func/main.sh
|
|
|
+source $HESTIA/conf/hestia.conf
|
|
|
+
|
|
|
+
|
|
|
+#----------------------------------------------------------#
|
|
|
+# Verifications #
|
|
|
+#----------------------------------------------------------#
|
|
|
+
|
|
|
+check_args '2' "$#" 'USER DOMAIN DEBUG'
|
|
|
+is_format_valid 'user' 'domain'
|
|
|
+is_object_valid 'user' 'USER' "$user"
|
|
|
+is_object_unsuspended 'user' 'USER' "$user"
|
|
|
+is_object_valid 'web' 'DOMAIN' "$domain"
|
|
|
+is_object_unsuspended 'web' 'DOMAIN' "$domain"
|
|
|
+
|
|
|
+# Perform verification if read-only mode is enabled
|
|
|
+check_hestia_demo_mode
|
|
|
+
|
|
|
+
|
|
|
+#----------------------------------------------------------#
|
|
|
+# Action #
|
|
|
+#----------------------------------------------------------#
|
|
|
+
|
|
|
+# Load domain data
|
|
|
+parse_object_kv_list $(grep "DOMAIN='$domain'" $USER_DATA/web.conf)
|
|
|
+
|
|
|
+# Check if web server is NGINX standalone
|
|
|
+if [ "$WEB_SYSTEM" != 'nginx' ]; then
|
|
|
+ echo "Error: NGINX not in Stand Alone mode"
|
|
|
+ exit $E_NOTEXIST
|
|
|
+fi
|
|
|
+
|
|
|
+
|
|
|
+if ! grep --quiet "forcessl" $HESTIA/data/templates/web/nginx/default.tpl; then
|
|
|
+ $BIN/v-update-web-templates
|
|
|
+fi
|
|
|
+fastcgi="$HOMEDIR/$user/conf/web/$domain/$WEB_SYSTEM.fastcgi_cache.conf"
|
|
|
+no_cache='$no_cache'
|
|
|
+cookie_session='$cookie_session'
|
|
|
+http_x_update='$http_x_update'
|
|
|
+status='$upstream_cache_status'
|
|
|
+
|
|
|
+cat << EOF > $fastcgi
|
|
|
+ fastcgi_cache $domain;
|
|
|
+ fastcgi_no_cache $no_cache;
|
|
|
+ fastcgi_cache_bypass $no_cache;
|
|
|
+ fastcgi_cache_bypass $cookie_session $http_x_update;
|
|
|
+EOF
|
|
|
+
|
|
|
+if [ ! -z "$debug" ]; then
|
|
|
+ echo " add_header \"X-STATUS\" \"$status\";" >> $fastcgi
|
|
|
+fi
|
|
|
+
|
|
|
+chown root:$user $fastcgi
|
|
|
+chmod 640 $fastcgi
|
|
|
+
|
|
|
+str="fastcgi_cache_path /var/cache/nginx/php-fpm/$domain levels=2"
|
|
|
+str="$str keys_zone=$domain:10m inactive=60m max_size=512m;"
|
|
|
+conf='/etc/nginx/conf.d/01_fast_cgi_caching_pool.conf'
|
|
|
+if [ -e "$conf" ]; then
|
|
|
+ if [ -z "$(grep "=${domain}:" $conf)" ]; then
|
|
|
+ echo "$str" >> $conf
|
|
|
+ fi
|
|
|
+else
|
|
|
+ echo "$str" >> $conf
|
|
|
+fi
|
|
|
+
|
|
|
+mkdir -p /var/cache/nginx/php-fpm/$domain
|
|
|
+
|
|
|
+#----------------------------------------------------------#
|
|
|
+# Hestia #
|
|
|
+#----------------------------------------------------------#
|
|
|
+
|
|
|
+if [ -z "$FASTCGI" ]; then
|
|
|
+ add_object_key "web" 'DOMAIN' "$domain" 'FASTCGI_CACHE' 'ALIAS'
|
|
|
+fi
|
|
|
+
|
|
|
+# Set FASTCGI flag to enabled
|
|
|
+update_object_value 'web' 'DOMAIN' "$domain" '$FASTCGI_CACHE' 'yes'
|
|
|
+
|
|
|
+# Restart web server
|
|
|
+$BIN/v-restart-web
|
|
|
+check_result $? "Web restart failed" > /dev/null
|
|
|
+
|
|
|
+# Logging
|
|
|
+log_history "enabled fast cgi support for $domain"
|
|
|
+log_event "$OK" "$ARGUMENTS"
|
|
|
+
|
|
|
+exit
|