The page cache needs no server rules. It works on Nginx out of the box. But Nginx does not read .htaccess files, so two things need a few lines in your server block.
Get your rules
Open the Cache tab, Browser and server card, and click Copy rules. The rules look like this:
location ~* \.(avif|eot|gif|ico|jpe?g|mp4|otf|png|svg|ttf|webm|webp|woff2?)$ {
expires 1y;
add_header Cache-Control "public";
access_log off;
}
location ~* \.(css|js)$ {
expires 1M;
add_header Cache-Control "public";
}
gzip on;
gzip_vary on;
gzip_comp_level 5;
gzip_types text/plain text/css text/javascript application/javascript application/json application/xml application/rss+xml application/atom+xml image/svg+xml font/ttf font/otf;
# Stored pages are served by PHP; nothing in this folder should be fetched directly.
location ^~ /wp-content/cache/softminal-cache/ {
deny all;
}
# The developer config file, if you use one.
location = /wp-content/softminal-cache.json {
deny all;
}
Please add the two deny all blocks even if you skip the rest. Apache reads the cache folder’s own protection file, but Nginx does not.
Add and reload
- Paste the rules inside your site’s
server { }block. - Test the config:
sudo nginx -t - Reload:
sudo systemctl reload nginx