How to update additional Nginx directives for several domains

Created:

2016-11-16 12:40:25 UTC

Modified:

2017-08-08 13:10:33 UTC

1

Was this article helpful?


Have more questions?

Submit a request

How to update additional Nginx directives for several domains

Applicable to:

  • Plesk 12.5 for Linux
  • Plesk Onyx for Linux

Question

How to add additional Nginx directives for several domains?

Answer

Warning: These instructions are applicable only if all the domains in the list do not have other additional nginx directives yet. Any existing directives will be overwritten.

Additional Nginx directives are saved in domain's configuration file:

/var/www/vhosts/system/example.com/conf/vhost_nginx.conf

To update additional Nginx directives for several domains use the following instruction:

  1. Connect to the server using SSH.
  2. Create the list of domains using a text editor:

    # vi domains_list

    example1.com
    example2.com

  3. Create the directive's template, for example as follows:

    # vi directive_template

    if ( !-e $request_filename ) {
    rewrite (/|\\.php|\\.html|\\.htm|\\.feed|\\.pdf|\\.raw|/[^.]*)$ /index.php last;
    break;
    }

  4. Create the script:

    # vi nginx_directives.sh

    #!/bin/bash
    cat domains_list | while read list;
    do
    for domain in $list
    do
    touch /var/www/vhosts/system/$domain/conf/vhost_nginx.conf;
    chown root:nginx /var/www/vhosts/system/$domain/conf/vhost_nginx.conf;
    cat directive_template > /var/www/vhosts/system/$domain/conf/vhost_nginx.conf;
    done;
    done;

  5. Make that script executable:

    # chmod +x nginx_directives.sh

  6. Execute the script:

    # ./nginx_directives.sh

Have more questions? Submit a request
Please sign in to leave a comment.