Absolutely! Implementing **full-page caching with Nginx** is one of the most powerful ways to dramatically boost WordPress performance, especially for **high-traffic sites** like yours (1k sustained users). This guide assumes you're using: - Nginx (not Apache) - PHP-FPM - WordPress - Linux (Ubuntu/Debian) --- ## ๐Ÿ”ง Step-by-Step: Full Page Caching with Nginx (FastCGI Cache) --- ### โœ… 1. **Prepare Directories** Create a directory for cached pages: ```bash sudo mkdir -p /var/cache/nginx/wordpress sudo chown -R www-data:www-data /var/cache/nginx ``` --- ### ๐Ÿง  2. **Understand the Cache Key** Nginx will cache based on: - URI - Host - Request method (GET/POST) - Cookies (important for logged-in vs public users) --- ### โš™๏ธ 3. **Nginx Configuration** Open your Nginx server block (e.g., `/etc/nginx/sites-available/yourdomain.com`) and make the following changes: #### a. Enable the cache zone Add this at the top of the file (outside the server block): ```nginx fastcgi_cache_path /var/cache/nginx/wordpress levels=1:2 keys_zone=WORDPRESS:100m inactive=60m use_temp_path=off; fastcgi_cache_key "$scheme$request_method$host$request_uri"; ``` #### b. Inside your `server {}` block Insert the following: ```nginx set $no_cache 0; # Don't cache POST requests or certain URIs if ($request_method = POST) { set $no_cache 1; } if ($query_string != "") { set $no_cache 1; } # Don't cache logged-in users or recent commenters if ($http_cookie ~* "comment_author_|wordpress_logged_in_|wp-postpass_") { set $no_cache 1; } ``` #### c. Inside your `location ~ \.php$` block Modify it to include FastCGI caching: ```nginx location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.2-fpm.sock; fastcgi_cache WORDPRESS; fastcgi_cache_bypass $no_cache; fastcgi_no_cache $no_cache; fastcgi_cache_valid 200 301 302 60m; add_header X-FastCGI-Cache $upstream_cache_status; fastcgi_cache_use_stale error timeout invalid_header http_500; } ``` This will: - Cache pages for 60 minutes - Avoid caching for logged-in users and POST requests - Add a response header like `X-FastCGI-Cache: HIT` or `MISS` --- ### ๐Ÿ’ก 4. **Purge Cache (Optional)** Nginx FastCGI Cache does not automatically purge pages when WordPress content is updated. **Options:** - Use [`nginx-cache-purge`](https://github.com/FRiCKLE/ngx_cache_purge) module (requires recompiling Nginx) - Use a plugin like [**Nginx Cache**](https://wordpress.org/plugins/nginx-helper/) which works well with Redis or FastCGI: ```php define('RT_WP_NGINX_HELPER_CACHE_PATH', '/var/cache/nginx/wordpress'); define('RT_WP_NGINX_HELPER_LOG_PATH', '/var/log/nginx/wordpress-helper.log'); ``` --- ### โœ… 5. **Reload Nginx** ```bash sudo nginx -t sudo systemctl reload nginx ``` --- ## ๐Ÿงช 6. **Test It** - Open a browser โ†’ Visit your homepage - Run: ```bash curl -I https://yourdomain.com ``` You should see: ```http X-FastCGI-Cache: HIT ``` Try again after logging in to WordPress. You should see: ```http X-FastCGI-Cache: BYPASS ``` --- ## ๐Ÿ” 7. **Optional: Clear Cache Manually** ```bash sudo rm -rf /var/cache/nginx/wordpress/* ``` --- ## ๐Ÿš€ Performance Gains | Without Cache | With Nginx FastCGI Cache | |---------------------|--------------------------| | 300โ€“800ms TTFB | 50โ€“100ms TTFB | | High CPU/PHP usage | Very low CPU usage | | DB load under traffic| Minimal DB activity |