Articles in this section

How to update the "Additional nginx directives" field for all/several domains in Plesk

kb: how-to Plesk for Linux ABT: Group A

Applicable to:

  • Plesk for Linux

Question

How to update the "Additional nginx directives" field for all/several domains?

Answer

For security reasons, additional nginx directives can be adjusted 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:

  1. Connect to your Plesk server via SSH.
  2. 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.org

    To add a list of all hosted domains to the file, run this command:

    # plesk bin site -l > domains_list

  3. 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;

  4. 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:

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.