Nginx: serving different robots.txt for SSL and non-SSL version of the website

From lxadm | Linux administration tips, tutorials, HOWTOs and articles
Jump to: navigation, search

Sometimes, you may want SSL (https://) version of your websites to have different robots.txt than the plain text version (http://).

Here is how to achieve it with nginx webserver:

        # serve different robots.txt for https
        location = /robots.txt {
            if ($server_port = 443) {
                rewrite ^ /robots_ssl.txt last;
            }
        }