Question
How to update the "Additional nginx directives" field for all/several domains?
Answer
For security reasons, it is possible to adjust additional nginx directives only for new domains by means of service plan settings (Service Plans > plan_name > Web Server > Additional nginx directives). Otherwise, new directives can overwrite existing configuration and break websites' functionality.
Additional nginx directives for existing domains can be adjusted via a command-line interface.
Domain's additional nginx directives are saved in the vhost_nginx.conf
configuration file which is located in /var/www/vhosts/system/example.com/conf
. To update additional nginx directives for all/several domains, apply the following steps:
-
Connect to a Plesk server via SSH.
-
Create a list of domains, nginx directives of which should be updated:
Warning: All existing nginx directives will be overwritten for these domains by the script. Make sure existing nginx directives can be safely overwritten.
2.1. Create a new file with the name
domains_list
:# touch domains_list
2.2. Add required domains to the created file. Each domain should be listed on a new line:
example.com
example.net
example.orgTo add a list of all hosted domains to the file, run this command:
# plesk bin site -l > domains_list
-
Create a file with nginx directives that should be added to the domains from step 2:
3.1. Create a new file with the name
directive_template
:# touch directive_template
3.2. Add required nginx directives to the file. For example:
Note: Make sure new additional nginx directives will not break nginx configuration. Before adding, test additional nginx directives on one domain in Plesk at Domains > example.com > Apache & nginx Settings.
proxy_send_timeout 1200s;
proxy_read_timeout 1200s;
fastcgi_send_timeout 1200s;
fastcgi_read_timeout 1200s;
proxy_buffers 8 16k;
proxy_buffer_size 32k;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k; -
Run the command below to apply the changes:
# while read -r domain; do install directive_template -o root -g nginx -m 600 "/var/www/vhosts/system/${domain}/conf/vhost_nginx.conf"; plesk sbin httpdmng --reconfigure-domain "${domain}" -no-restart; done < domains_list && service nginx reload
Alternative solutions:
-
Set these directives in the custom nginx configuration file according to this Plesk Documentation page.
-
Add required nginx directives to the global nginx configuration file according to this KB article.