I'm implementing a sort of url-shortener service. What happens is that I have some backend app server that takes in a request, does some computation and returns a 301 redirected url back upstream to an nginx frontend:

request --->   nginx  ---->  app_server

What I want to be able to do is cache this returned 301 url for the same request (a specific url with a "short code").

Does nginx do this caching automatically? Or should I drop in something like varnish in between nginx and the app_server? I can easily cache this in memcache, but that would require hitting the app_server, which I'm sure can be dispensed with after the first request.

Thanks.

link|improve this question
feedback

2 Answers

You can configure Nginx to do that.

Example: to cache a redirect (301 or 302) up to 60 minutes:

proxy_cache_valid 301 302 60m;
link|improve this answer
feedback

I am also researching this and from what I understand Varnish does redirects very indirectly. And the same for proxy caching in Nginx. So from what I understand we need Varnish for caching and upstreams and Nginx only for redirects?

This is probably not specific for your application though.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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