I want to create an alias to the "static" folder:
location ~ ^/myapp/([a-zA-Z0-9_-]+)/ {
alias /var/lib/myapp/$1/static/;
autoindex on;
}
But, if I have the URL:
I'm being redirected to:
which causes a 404.
If I access:
I can correctly see the list of all the html files (because of "autoindex on").
However, if I have this config:
location /myapp/ {
alias /var/lib/myapp/;
autoindex on;
}
nginx does NOT add the trailing slash, and therefore I can correctly access the .html pages. The problem with this config is that "static/" has to be included in the URL, such as:
How can I make nginx NOT add a trailing slash in the first example above?
An
alias
within a regular expressionlocation
block requires a value which specifies the full path to the target file. You need to capture the remainder of the URI in thelocation
statement and append it to the end of thealias
statement.For example:
See this document for details.