How to add additional nginx directives globally




  • Avatar
    Mark Collis


    I have tried this but with no luck

    I want to do a server rule which redirects the public IP address to the domain (not using .htaccess)  so ...

    curl -I http://<IP Address>
    curl -I https://<IP Address> 

    goes 301 to


    I tried putting the server rule below in the additional nginx directives but this is not allowed so found this article and tried directives.conf but it not working.

    server {
        listen 80;
        listen 443;
        server_name <IP Address>;
        return 301$request_uri;

    We have

    OS: CentOS Linux 7.3.1611 (Core)
    Product: Plesk Onyx 17.5.3 Update #39

    Any help appreciated




  • Avatar
    Ivan Postnikov

    @Mark Collis


    The configuration you have provided looks valid.
    Consider contacting Nginx Support, as they are professionals in their product

  • Avatar
    Karl May

    Is here a example for append something like this in server {...} for all vhosts? (without service plan)

    if ($is_badbot = 1) {
            return 444;
  • Avatar
    Ivan Postnikov

    Hello @Karl,

    We do not have examples prepared by us but give a try to this solution:

    Please, note that this was not tested with Plesk and will be done at your own risk.

  • Avatar
    Karl May

    Thanks for reply, but I don't understand in which way this is a solution? The question was how I can add this lines in quote to all vhost nginx config-files.


    I expected a answer like
    # for filename in `find /var/www/vhosts/system/*/conf/ -name vhost_nginx.conf`; do echo $filename; cat add_new_vhost_conf.txt >> $filename; done

    offtopic: your link is version 1, current version 3 is this link 

  • Avatar
    Ivan Postnikov

    Ok @Karl,

    Thank you for clarification.

    This script appeds the configuration from specified file "add_new_vhost_conf.txt":

    plesk db -Ne "select from domains;" > domains.txt
    while read i
    cat add_new_vhost_conf.txt >> /var/www/vhosts/system/$i/conf/nginx.conf
    done < domains.txt

    Check it, it case it will not suit, try using "sed" command if adding test will be needed to specific place in configuration.

    Also, please note that such manual web server configuration is not recommended and may be overwritten after updates or domains reconfiguration.

Please sign in to leave a comment.

Have more questions? Submit a request