Applicable to:
- Plesk for Linux
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:
CONFIG_TEXT: 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.
CONFIG_TEXT: 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.
Comments
5 comments
I've got another workflow that set the directive, but it doesn't take effect.
Even if I try to restart the nginx service with
I also checked the user and group and permission.(root:nginx and 644)
// EDIT
Works with
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain <domain>
@Jason, thank you for noticing, the script will be updated soon.
Is this really the only way to do this? What about apache?
Hi, @Robert Perrett.
You can use the same approach as for nginx, but using vhost.conf and vhost_ssl.conf (for Additional Apache directives for HTTP and HTTPS correspondingly).
As an alternative, you can add required directives to configuration template: Changing Virtual Hosts Settings Using Configuration Templates
I did this with a slightly different approach. I created a tmp file with my directives then looped over the domains in .../vhosts/system/ to overwrite the existing vhost_nginx.conf, restart apache+nginx and you're done.
5 Steps:
# nano /tmp/vhost_nginx.conf (pasted my directives into here and saved)
# cd /var/www/vhosts/system/
# for d in */; do cp /tmp/vhost_nginx.conf "./$d/conf"; done
# service nginx restart
# service httpd restart
Please sign in to leave a comment.