nginx: Location block for all URIs without extension
I know how to process URIs that match a certain pattern.
Example
The following configuration will add an Cache-Control http-header to all files ending with .css or .js:
location ~* \.(css|js)$ {
add_header Cache-Control "public, max-age=31536000, immutable" always;
}
Question
How can I process all URIs without extension?
Something like www.domain.tld/my-article
.
(I use nginx as an reverse-proxy and I add the extension .html
in the .htaccess
.)
Solution 1:
The usual way is:
location / {
# Everything else
}
location ~* \.(?:css|js)$ {
add_header Cache-Control "public, max-age=31536000, immutable" always;
}
nginx location directive documentation explains in detail how nginx evaluates different location
blocks.