How to add additional nginx directives globally on a Plesk server

Follow

Comments

9 comments

  • Avatar
    Mark Collis

    Hi 

    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>
    and 
    curl -I https://<IP Address> 

    goes 301 to https://www.domain.com

     

    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 https://www.domain.com$request_uri;
    }

    We have

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

    Any help appreciated

    Mark

     

     

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    @Mark Collis

    Hi!

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

    0
    Comment actions Permalink
  • 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;
    }
    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    Hello @Karl,

    We do not have examples prepared by us but give a try to this solution: https://github.com/mariusv/nginx-badbot-blocker

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

    0
    Comment actions Permalink
  • 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.

    /var/www/vhosts/system/domain1.com/conf/vhost_nginx.conf
    /var/www/vhosts/system/domain2.com/conf/vhost_nginx.conf

    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 https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker 

    0
    Comment actions Permalink
  • Avatar
    Ivan Postnikov

    Ok @Karl,

    Thank you for clarification.

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

    #!/bin/bash
    plesk db -Ne "select domains.name from domains;" > domains.txt
    while read i
    do
    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.

    0
    Comment actions Permalink
  • Avatar
    Learning Curve

    Hi, we'd like to globally add these two "include" statements:

    include /etc/nginx/bots.d/blockbots.conf;
    include /etc/nginx/bots.d/ddos.conf;

    If we follow the instructions (above) exactly, an error relating to the blockbots.conf file not being allowed in this location is recieved. That's easy to correct as follows:

    server {
        include /etc/nginx/bots.d/blockbots.conf;
        include /etc/nginx/bots.d/ddos.conf;
    }

    but although that ^ config is correct (i.e. no nginx errors)... the settings are NOT applied globally, No related changes are visible at all, after re-starting nginx (via curl tests etc).

    If instead, we add the 1st version of the above, to 'Additional nginx directives' via Plesk Panel GUi and/or /var/www/vhosts/system/**my-domain**/conf/vhost_nginx.conf via CLI (the 2nd version is - correcty - not permitted) then when tested, via curl afterwards, everything DOES work correctly (on that specific domain) with all of the permitted bots, but the error on all of the banned bots is as follows: curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1).

    Obviously, we'd prefer to apply these two "include" statements globally (not individually on each hosted domain...) but creating a /etc/nginx/conf.d/directives.conf file as per above and which includes them - currently - doesn't work. What did we miss? :o))

     

    0
    Comment actions Permalink
  • Avatar
    Learning Curve

    That last post was a week ago now... Any tech response from Plesk yet?

    Ivan Postnikov / Kuzma Ivanov

    0
    Comment actions Permalink
  • Avatar
    Learning Curve

    Why would Plesk publish what are usually very helpful / time saving articles, if, there is then: Zero response to relevant questions relating to the article itself? That seems like a very strange logic?

    Ivan Postnikov Kuzma Ivanov

    0
    Comment actions Permalink

Please sign in to leave a comment.

Have more questions? Submit a request