Confused by documentation for /alias/

Hi

From: http://wiki.nginx.org/HttpCoreModule

BEGIN
For example:

location ~ ^/download/(.*)$ {
alias /home/website/files/$1;
}
The request “/download/book.pdf” will return the file
“/home/website/files/book.pdf”. Note again that only part of the request
URI after the location is appended to the path defined by alias.
END

Why doesn’t this return the directory “home/website/files/book.pdf/” ?

Posted at Nginx Forum:

Hi,

Because of the $ symbol on the location line which marks ‘end of line’.
Remove the $ symbol and you’ll have book.pdf/ working.

Boyko

I understand the regexp. $1 = book.pdf

So for the specific request in the example, we could write:

location ~ ^/download/(.*)$ {
alias /home/website/files/book.pdf;
}

Is it that the example is unrealistic? Because this config does exactly
the same thing:
location /download/ {
alias /home/website/files/;
}

I’m struggling to see the difference, and why one would use the regexp.

How about requesting “/download/baz/foo/book.pdf” for the above regexp
config and this one:
location ~ ^/download/(.*)/foo/ {
alias /home/website/files/$1;
}

(why would I do this?)

Posted at Nginx Forum: