Nginx: Can I cache a URL matching a pattern at a different URL?
- by Josh French
I have a site with some URLs that look like this: /prefix/ID, where /prefix is static and ID is unique. Using Nginx as a reverse proxy, I'd like to cache these pages at the /ID portion only, omitting the prefix.
Can I configure Nginx so that a request for the original URL is cached at the shortened URL?
I tried this (I'm omitting some irrelevant parts) but obviously it's not the correct solution:
http {
map $request_uri $page_id {
default $request_uri;
~^/prefix/(?<id>.+)$ $id;
}
location / {
proxy_cache_key $page_id
}
}