I just read this Digital Ocean article and was wondering if the topology in the final example can be implemented with nginx.
I'm interested in how the load balancer handles the two dedicated cache servers that are NOT in front of the application servers. They describe the process like this:
- The load balancer checks cache-backend to see if the requested content is cached (cache-hit) or not (cache-miss)
- If cache-hit: return the requested content to the load balancer and jump to Step 7. If cache-miss: the cache server forwards the request to app-backend, through the load balancer
- The load balancer forwards the request through to app-backend
- app-backend reads from the database then returns requested content to the load balancer
- The load balancer forwards the response to cache-backend
- cache-backend caches the content then returns it to the load balancer
- The load balancer returns requested data to the user
I guess the load balancer should have the two groups in upstream directives:
upstream cachebackend {
server cache-1.example.com;
server cache-2.example.com;
}
upstream appbackend {
server app-1.example.com;
server app-2.example.com;
}
and then from inside a server directive:
location / {
proxy_pass http://cachebackend;
# if that one is a MISS, request this one:
# proxy_pass http://appbackend;
# and then save the response on the cachebackend
# before returning it to the client
}
I want to know how to tell nginx to follow the steps above, or if it's possible at all.
Thanks :)