nginx conf:

location / {
            rewrite ^/cache.html$ /cache.jsp last;
location ~ \.jsp {
            #if I add proxy_cache here,will be cache every JSP file,I don't want it
#location ~ \.html {
            #I want cache all ".html" page,but it's not work.
            #proxy_cache cache;

I using a rewrite rule to mapping /cache.html to /cache.jsp

I want to access http//localhost/cache.html to cache page,

but access http//localhost/cache.jsp with out cache,

how to do? thanks for help :)

1 Answer 1


That is not possibly simply using rewrite rules.

The only way you could make it work is by proxying back to the page and enabling proxy caching.

You could write custom locations to have it only cache specific page extensions and you can use if statements to set one-off cache keys to make it appear like a page is uncached, even though it is actually cached for 1 view.

If you're thinking of stepping in to the realms of real rule-based caching I'd recommend using Varnish instead.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .