Serving an alternate robots.txt for SSL requests.

Juan Fco. Giordana juangiordana at gmail.com
Wed Jan 14 02:15:07 MSK 2009


Thank you Nick for your help,

I've followed your suggestions and it worked as expected.

I've changed the rewrite rule since I don't need to capture anything there.

server {
     listen 443;
     [...]
     location = /robots.txt {
         rewrite ^    /robots_ssl.txt last;
     }
}

Does anybody know if this is possible to do within a single server 
context that handle both protocols in version 0.7.*?

Thanks.

On 2009-01-07 15:23:26 Nick Pearson wrote:
> Hi Juan,
> 
> Try using two server directives -- one for http and one for https.  The
> server directive chosen depends on the port that is requested.  Something
> like this:
> 
> server {
>     listen  80;  # http
>     server_name  www.yoursite.com;
>     [...]
>     location /robots.txt {
>         break;
>     }
> }
> server {
>     listen  443;  # https
>     server_name  www.yoursite.com;
>     [...]
>     location /robots.txt {
>         rewrite (.*)  /robots_ssl.txt;
>     }
> }






More information about the nginx mailing list