How to set robots.txt globally in nginx for all virtual hosts

Posted by anup on Server Fault See other posts from Server Fault or by anup
Published on 2013-10-29T08:06:14Z Indexed on 2013/10/29 9:57 UTC
Read the original article Hit count: 342

Filed under:
|
|

I am trying to set robots.txt for all virtual hosts under nginx http server. I was able to do it in Apache by putting the following in main httpd.conf:

<Location "/robots.txt">
    SetHandler None
</Location>
Alias /robots.txt /var/www/html/robots.txt

I tried doing something similar with nginx by adding the lines given below (a) within nginx.conf and (b) as include conf.d/robots.conf

location ^~ /robots.txt {
        alias /var/www/html/robots.txt;
}

I have tried with '=' and even put it in one of the virtual host to test it. Nothing seemed to work.

What am I missing here? Is there another way to achieve this?

© Server Fault or respective owner

Related posts about nginx

Related posts about robots.txt