Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 :)

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.