Applicable to:
- Plesk Onyx for Linux
Question
How to enable Serve static files directly by nginx by default in Domains > example.com > Apache & Nginx Settings?
Answer
As of now, this functionality is not implemented in Plesk. Vote for this feature at Plesk UserVoice portal.
The top-ranked suggestions are likely to be included in the next versions of Plesk.
As a workaround, this can be enabled by using Event Handler. It can be done either via Plesk GUI or via CLI.
-
Go Tools Settings > Event Manager > Add Event Handler.
-
Set fields as follows:
Event:CONFIG_TEXT: Default domain (the first domain added to a subscription) created
Priority:
CONFIG_TEXT: 0 (lowest)
User:
CONFIG_TEXT: root
Command:
CONFIG_TEXT: bash /usr/local/psa/bin/trigger.sh
-
Create
trigger.sh
script in /usr/local/psa/bin:-
Connect to the server via SSH
-
Create trigger.sh as follows:
# touch /usr/local/psa/bin/trigger.sh
-
Use any text editor to add the following lines to the file:
CONFIG_TEXT: #!/bin/bash
sleep 10
date >> /tmp/log 2>&1
echo $NEW_DOMAIN_NAME >> /tmp/log 2>&1
plesk bin subscription --update-web-server-settings $NEW_DOMAIN_NAME -nginx-serve-static true -nginx-static-extensions "ac3 avi bmp bz2 css cue dat doc docx dts eot exe flv gif gz htm html ico img iso jpeg jpg js mkv mp3 mp4 mpeg mpg ogg pdf png ppt pptx qt rar rm svg swf tar tgz ttf txt wav woff woff2 xls xlsx zip" >> /tmp/log 2>&1Note:
-nginx-serve-static
can take the values of true or false and-nginx-static-extensions
should be used to specify all the extensions we want to be served by nginx. -
Create a new domain. It will have Serve static files by nginx enabled by default.
-
Note: "Default domain created" handler is applied for newly created subscriptions only. Use "Domain created" handler and plesk bin domain --update
command in case it is required to do that for additional domains on the subscription.
-
Login to the server via SSH.
-
Create trigger.sh as follows:
# touch /usr/local/psa/bin/trigger.sh
-
Use any text editor to add the following lines to the file:
CONFIG_TEXT: #!/bin/bash
sleep 10
date >> /tmp/log 2>&1
echo $NEW_DOMAIN_NAME >> /tmp/log 2>&1
plesk bin subscription --update-web-server-settings $NEW_DOMAIN_NAME -nginx-serve-static true -nginx-static-extensions "ac3 avi bmp bz2 css cue dat doc docx dts eot exe flv gif gz htm html ico img iso jpeg jpg js mkv mp3 mp4 mpeg mpg ogg pdf png ppt pptx qt rar rm svg swf tar tgz ttf txt wav woff woff2 xls xlsx zip" >> /tmp/log 2>&1 -
Create Event Handlers with following commands:
# plesk bin event_handler --create -command "bash /usr/local/psa/bin/trigger.sh" -priority 0 -user root -event domain_create
# plesk bin event_handler --create -command "bash /usr/local/psa/bin/trigger.sh" -priority 0 -user root -event subdomain_create
Comments
3 comments
Update current host using this command
mysql -Ns -uadmin -p`cat /etc/psa/.psa.shadow` -D psa -e 'select name from dns_zone ORDER BY name ASC' | awk '{print "plesk bin subscription --update-web-server-settings " $1 " -nginx-serve-static true -nginx-static-extensions \"ac3 avi bmp bz2 css cue dat doc docx dts eot exe flv gif gz htm html ico img iso jpeg jpg js mkv mp3 mp4 mpeg mpg ogg pdf png ppt pptx qt rar rm svg swf tar tgz ttf txt wav woff woff2 xls xlsx zip\" " }' | sh
You can use the following code to add event without logging in to Plesk panel
Hello @Mehmet,
Thank you for your input!
As for the update of web server settings for all domains:
Usually Serve static files directly by nginx can be enabled for all domains with the following command:
# plesk bin site -l | while read i; do plesk bin domain --update-web-server-settings $i -nginx-serve-static true; done
More information on this matter you can also find in the following article: How to update web server settings for all domains via CLI
As for the creation of Event Handlers via CLI:
The article was modified accordingly.
Please sign in to leave a comment.