After many hours getting nginx to serve single files such as robots.txt (hint: clear your browser cache each time), I wound up with two different ways, one using the alias directive, and one using the root directive, like so:

location /robots.txt { alias /home/www/static/robots.txt; }
location /robots.txt { root /home/www/static/;  }

Is there any functional difference between the two? Or security issues? Any conflicts with other directives? (Both seemed fine with another /static location). Or any reason to pick one over the other?

Note - I didn't use both at the same time :) Rather I tried each, one at a time, and both worked. I'm not asking how they both interact together in the same file, but which one would be better to use.

link|improve this question

75% accept rate
feedback

1 Answer

up vote 6 down vote accepted

Well, these two directives are slightly functional different because you do not use exact match in the latter case. So, /robots.txt1111 will match your second location too.
location =/robots.txt { root /home/www/static/; } is an exact functional equivalent of your first directive.

link|improve this answer
Good point, thanks. But you can use an = in both cases, correct? Or does it only apply to root? Also, see my edit - I didn't mean to use both at once. :) – Cyclops Jun 8 '11 at 17:20
@Cyclops yes, you may use = in both cases. – Alexander Azarov Jun 9 '11 at 7:52
So they would be the same - is there any reason to pick one directive over the other? Is my main question. – Cyclops Jun 9 '11 at 13:36
@Cyclops Basically, there is no such reason. – Alex Jun 9 '11 at 14:05
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.