Applicable to:
- Plesk for Linux
Symptoms
When set Nginx Cache size and/or Cache timeout to 0
in Plesk > Domains > example.com > Apache & Nginx Settings > Enable Nginx caching Plesk shows a successful message:
CONFIG_TEXT: Information: The settings were successfully updated.
However, the configuration is broken:
-
The following errors are logged in the file
/var/log/plesk/panel.log
:CONFIG_TEXT: DEBUG [panel] Template_Exception: nginx: [emerg] invalid max_size value "max_size=" in /etc/nginx/plesk.conf.d/vhosts/example.com.conf:6
nginx: configuration file /etc/nginx/nginx.conf test failed
file: /usr/local/psa/admin/plib/Template/Writer/Webserver/Abstract.php
line: 75
code: 0
trace: #0 /usr/local/psa/admin/plib/Template/Configuration/Applier.php(200): Template_Writer_Webserver_Abstract->test()
...
#12 /usr/local/psa/admin/sbin/nginxmng(4): require_once(string '/usr/local/psa/admin/plib/api-cli/CliUtilityRunner.php') -
The following error can be shown:
PLESK_ERROR: New configuration files for the Apache web server were not created due to the errors in configuration templates: nginx: [emerg] invalid time value "" in /etc/nginx/plesk.conf.d/vhosts/example.com.conf:91 nginx: configuration file /etc/nginx/nginx.conf test failed
Cause
Product issue:
- #PPPM-12428 "Improved the nginx cache size validation."
Fixed in:- Plesk Obsidian 27 October 2020 (Linux)
Resolution
Workaround
If update is not possible for some reason you may try the following
Set a value higher than 0
:
-
Connect to the server via SSH
-
Create a list containing the domains with Nginx caching enabled:
# mysql -uadmin -p`cat /etc/psa/.psa.shadow` -D psa -Ne "select d.id, d.name from domains d, dom_param dp, WebServerSettingsParameters ws where d.id = dp.dom_id and dp.param = 'webServerSettingsId' and dp.val = ws.webServerSettingsId and ws.name = 'nginxCacheEnabled' and ws.value = 'true'" > /tmp/domainsList.txt
-
Identify the domains with a non-existing
Cache size:
# echo "-> START"; cat /tmp/domainsList.txt | while read ID DOM; do CHECK=`mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -D psa -Ne "select d.id from domains d, dom_param dp, WebServerSettingsParameters ws where d.id = dp.dom_id and dp.param = 'webServerSettingsId' and dp.val = ws.webServerSettingsId and ws.name = 'nginxCacheSize' and d.id = $ID" | wc -l`; if [ $CHECK -eq 0 ]; then echo -e "--> Domain: $DOM\t ID: $ID"; fi; done; echo "-> FINISH"
Cache timeout:
# echo "-> START"; cat /tmp/domainsList.txt | while read ID DOM; do CHECK=`mysql -uadmin -p$(cat /etc/psa/.psa.shadow) -D psa -Ne "select d.id from domains d, dom_param dp, WebServerSettingsParameters ws where d.id = dp.dom_id and dp.param = 'webServerSettingsId' and dp.val = ws.webServerSettingsId and ws.name = 'nginxCacheTimeout' and d.id = $ID" | wc -l`; if [ $CHECK -eq 0 ]; then echo -e "--> Domain: $DOM\t ID: $ID"; fi; done; echo "-> FINISH"
Note: The previous command will show an output as follows:
CONFIG_TEXT: -> START
--> Domain: example.com ID: 3
-> FINISH -
Go to Domains > example.com > Apache & Nginx Settings > Enable Nginx caching
-
Set a value higher than
0
for Cache size/Cache timeout -
Click the OK button
Note: Repeat steps 5-7 for all domains from the list that was fetched on step 3.
Event if bug already fixed there can be situation when values still set to 0 for domains and no records exist in Plesk database. In such case it is possible to launch the script below to set default values for Cache size (64Mb) and timeout (5 sec) for ALL domains with enabled Nginx caching:
# for i in `plesk db -N -e "select d.name from domains d, dom_param dp, WebServerSettingsParameters ws where d.id = dp.dom_id and dp.param = 'webServerSettingsId' and dp.val = ws.webServerSettingsId and ws.name = 'nginxCacheEnabled' and ws.value='true'"`; do plesk bin subscription --update-web-server-settings $i -nginx-cache-timeout 5 -nginx-cache-size 67108864;done
Comments
2 comments
Hello, unfortunately this solution did not solve the problem for me.
This is what i obtain on step 5 - 7: (the same happens if i clear the contents of "Additional nginx directives" field)
Hello Gianluca
According to the error message, the configuration file
contains an invalid value for "max_size".
Try the default one "max_size=67108864"
The issue isn't connected with this article. The reported error just blocks any changes due to incorrect Nginx configuration.
Please sign in to leave a comment.