title: Nginx: In which order rate limiting and caching are executed?
body: <p>I want to use nginx for rate limiting and caching. </p>
  
  <p>In which order nginx applies them? In other words, is it limiting only request to the upstream server or all requests (including cache HIT's)? </p>
  
  <p>How can this order be changed? I think it can be changed by having two <code>server</code> contexts. So, for example, on one <code>server</code> performs caching. It has the second <code>server</code> context as upstream. The second one limits requests to the "real" upstream. But that's probably not the most efficient way...</p>