wordpress-nginx
wordpress-nginx copied to clipboard
Wp Rocket Nginx Question
Inside location you have put:
expired modified 30m; add_header "Cache-Control" "must-revalidate";
Wouldn't the following be better? add_header Cache-Control "max-age=1800, must-revalidate";
Good point.
Expires can accept modified option that is optional. If someone prefers expires 30m, all they need to do is to remove the text 'modified' so that the expires header is based on access time which is exactly what add_header Cache-Control "max-age=1800, must-revalidate"; means (30 minutes from access time).
In its current form (expires modified 30m), it could mean any value for max-age depending on when the file was modified last time. So, if a file is modified 1 hour ago and if the file is accessed now (with expires modified 30m) header, then the value of max-age becomes zero. Basically, the visitor is accessing a file that is expired. So, we can set the value of max-age dynamically with the line expires modified 30m. Of course, it may not suit every site. For example, for low traffic sites, it is not recommended to keep modified or if we still need modified for a low traffic site, then it could be set something like expires modified 86400m, depending on how often the cache is refreshed or updated. Also, with this format expires modified 30m, we will be able to see exactly how long the cached content is valid, as max-age value changes all the time, if the file is refreshed 30 minutes ago or earlier.
The best way to understand the difference would be to apply both configurations (one at a time) in the same site and see how the headers vary between the configurations.
I hope you get the point. If not, please reply back. Thanks.
Hi again, I have another question.
What happens if WP Rocket-Cache hasn't created a cache file yet?
try_files "/wp-content/cache/wp-rocket/$host${uri}$is_args$args/index$https_suffix.html" $uri $uri/ /index.php$is_args$args;
How will Nginx interpret this line above?
It is a four step process. Let's take home page as example with no cache generated yet.
- Nginx looks for cached content. It is not available. So, it moves on.
- As / if the cache is not ready, it looks for the exact URL in the hard disk. Since almost 100% of the requests are dynamic in nature, Nginx will not find it in the hard disk. So, it moves on.
- Nginx looks for "URL with a trailing slash". Like previous step, home page is generated dynamically. So, Nginx will not find any physical file to serve from hard disk and will move on.
- Nginx passes the requested URL to WordPress/PHP (to generate the content dynamically).