11#! /bin/bash
2- # info: Adding fast cgi nginx support
2+ # info: Adding FastCGI nginx support
33# options: USER DOMAIN [DEBUG]
44# labels: hestia web
55#
6- # example: v-add-web-domain-fast-cgi -cache user domain.tld
6+ # example: v-add-fastcgi -cache user domain.tld
77#
8- # Function enables fast cgi support for Nginx
9- # Add "yes" as last parameter append debug information to response headers
8+ # Function enables FastCGI cache for nginx
9+ # Add "yes" as last parameter to append debug information to response headers
1010
1111
1212# ----------------------------------------------------------#
@@ -45,16 +45,16 @@ check_hestia_demo_mode
4545# Load domain data
4646parse_object_kv_list $( grep " DOMAIN='$domain '" $USER_DATA /web.conf)
4747
48- # Check if web server is NGINX standalone
48+ # Check if nginx is not in proxy mode
4949if [ " $WEB_SYSTEM " != ' nginx' ]; then
50- echo " Error: NGINX not in Stand Alone mode"
50+ echo " Error: nginx is in proxy mode"
5151 exit $E_NOTEXIST
5252fi
5353
54-
5554if ! grep --quiet " forcessl" $HESTIA /data/templates/web/nginx/default.tpl; then
5655 $BIN /v-update-web-templates
5756fi
57+
5858fastcgi=" $HOMEDIR /$user /conf/web/$domain /$WEB_SYSTEM .fastcgi_cache.conf"
5959no_cache=' $no_cache'
6060cookie_session=' $cookie_session'
@@ -63,9 +63,11 @@ status='$upstream_cache_status'
6363
6464cat << EOF > $fastcgi
6565 fastcgi_cache $domain ;
66- fastcgi_no_cache $no_cache ;
66+ fastcgi_cache_valid 200 2m;
67+ fastcgi_cache_valid 301 302 10m;
68+ fastcgi_cache_valid 404 10m;
6769 fastcgi_cache_bypass $no_cache ;
68- fastcgi_cache_bypass $cookie_session $http_x_update ;
70+ fastcgi_no_cache $no_cache ;
6971EOF
7072
7173if [ ! -z " $debug " ]; then
7577chown root:$user $fastcgi
7678chmod 640 $fastcgi
7779
78- str=" fastcgi_cache_path /var/cache/nginx/php-fpm /$domain levels=2"
79- str=" $str keys_zone=$domain :10m inactive=60m max_size=512m;"
80- conf=' /etc/nginx/conf.d/01_fast_cgi_caching_pool .conf'
80+ str=" fastcgi_cache_path /var/cache/nginx/micro /$domain levels=1: 2"
81+ str=" $str keys_zone=$domain :10m max_size=512m inactive=30m ;"
82+ conf=' /etc/nginx/conf.d/fastcgi_cache_pool .conf'
8183if [ -e " $conf " ]; then
8284 if [ -z " $( grep " =${domain} :" $conf ) " ]; then
8385 echo " $str " >> $conf
8688 echo " $str " >> $conf
8789fi
8890
89- mkdir -p /var/cache/nginx/php-fpm /$domain
91+ mkdir -p /var/cache/nginx/micro /$domain
9092
9193# ----------------------------------------------------------#
9294# Hestia #
@@ -96,15 +98,15 @@ if [ -z "$FASTCGI" ]; then
9698 add_object_key " web" ' DOMAIN' " $domain " ' FASTCGI_CACHE' ' ALIAS'
9799fi
98100
99- # Set FASTCGI flag to enabled
101+ # Set FastCGI cache flag to enabled
100102update_object_value ' web' ' DOMAIN' " $domain " ' $FASTCGI_CACHE' ' yes'
101103
102104# Restart web server
103105$BIN /v-restart-web
104106check_result $? " Web restart failed" > /dev/null
105107
106108# Logging
107- log_history " enabled fast cgi support for $domain "
109+ log_history " Enabled FastCGI cache for $domain "
108110log_event " $OK " " $ARGUMENTS "
109111
110112exit
0 commit comments