1

I have some questions about caching implementation since most of the resources I have found don’t seem to distinguish between NGINX as a reverse proxy or as a “native” web host.

I’ve setup a WordPress server on a LEMP stack (so NGINX as a “native” web host) which sits behind a separate NGINX reverse proxy. For caching, I have implemented fastcgi_cache on the server hosting WordPress. My reasoning is that since that server is handling the php anyway, it makes the most sense to cache it here locally since it’s on the same machine. That way, if I get .php request from the reverse proxy on my upstream server, it’s already there and waiting.

1) Is this logic sound/correct or should I still be handling the fastcgi_cache on the reverse proxy?

On my reverse proxy, which is also running NGINX, I have it setup to proxy_pass http traffic to the above WordPress server. I am going to have it browser cache static content (like .js, .css). Additionally, I am planning on having the reverse proxy proxy_cache the HTTP traffic it normally would’ve forwarded to the WordPress upstream. I will exclude certain locations from proxying (/wp-admin/, cookies, etc). My logic is that it makes the most sense to handle the HTTP proxy_cache here since it’s closest to the client.

2) Is this the appropriate way to handle this?

3) Will the requests for .php files still make it through to my WordPress server to be handled by the fastcgi_proxy/fastcgi_cache? My guess/concern is that it wouldn’t since these requests are afterall still HTTP requests.

Tl;dr: I have two NGINX servers: One hosting WordPress and another serving as a reverse proxy. I am planning on proxy_caching on the reverse proxy and fastcgi_caching on the WordPress server. Is this configuration acceptable?

These questions aren’t necessarily just for my specific application but also to help me understand how exactly NGINX is supposed to work. Thanks in advance!

1

It depends on the nature of your site. If there is not dynamic content, then it is safe to cache using nginx.

The problem with caching in nginx is to signal nginx properly on content changes. The problem will be even bigger in your two caching server setup.

If you have dynamic content on your site, then I suggest using W3 Total cache for caching, as it can properly invalidate the caches.

  • Thanks for your response. This is more of a learning project for me to gain more knowledge of NGINX/web development in general. My understanding of WordPress is that it's basically all dynamic content (i.e. everything is just rendered from php), so without fastcgi caching, almost nothing would be cached, correct? (Obviously this wouldn't apply to .js, .css, etc.) Like you said, that means you obviously need purge control to update the cache which is going to be my next major PHP project. – StudentDeveloper7 Jan 10 at 2:18
  • Yes, WordPress generates all content dynamically. But I was referring to the actual nature of the site content. If it is static in a sense that the content does not change often, then nginx caching is usable. – Tero Kilkanen Jan 12 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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