How to add additional nginx directives globally

Follow

Comments

6 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

Please sign in to leave a comment.

Have more questions? Submit a request