mardi 1 mai 2018

Do i need to declare if statement in each server block

I have a bot blocking map that I am using that makes nginx respond with 444. I have "if" blocks in each server block and it works, but i want to know if just putting it at the top in its own server block would be better, or how exactly should i be doing it?

Currently, my domainname.org.conf file has 3 server blocks. The first block does insecure and secure redirect from old domain requests to the new domain (we rebranded). The second block handles redirecting domainname.org to www.domainname.org. The third block actually has the meat and potatoes for PHP and whatnot.

here is the conf, with some data omitted and obfuscated.

server {
    listen 80;
    listen 443;

    MY CERT STUFF IS HERE BUT I'M NOT SHARING DETAILS

    server_name olddomainname.org *.olddomainname.org;

    #blocks blank user_agents
    if ($limit_bots = 1) {
        return 444;
    }

    return 301 https://www.newdomainname.org$request_uri;

}

#############################################################################################
# THIS SERVER BLOCK SIMPLY ACCEPTS ANY INCOMING NON-SUBDOMAININSECURE DOMAIN AND REROUTES IT TO A SECURE ONE
# IT ONLY AFFECTS THE PROD WEBSITE. IT SHOULD NOT INTERFERE WITH ANY DEVELOPMENT SUBDOMAINS

server {
    listen 80;
    listen 443;
    server_name newdomainname.org;

    #blocks blank user_agents
    if ($limit_bots = 1) {
        return 444;
    }

    return 301 $scheme://www.newdomainname.org$request_uri;
}

#############################################################################################
# THIS SERVER BLOCK HANDLES ANY INCOMING INSECURE SUBDOMAIN


server {
    listen 80;
    listen 443 default ssl;

   MY CERT STUFF IS HERE BUT I'M NOT SHARING DETAILS

    server_name www.newdomainname.org;

    #blocks blank user_agents
    if ($limit_bots = 1) {
        return 444;
    }

    ## Redirect 80 to 443
    if ($scheme = http) {
       return 301 https://$server_name$request_uri;
    }


    root /var/www;

This works, but adds repetition.

Aucun commentaire:

Enregistrer un commentaire