Profile

How to enable fastcgi_cache caching in Pagoda Panel Nginx? WordPress speedup

Enable fastcgi_cache cache
Article List
Article List

FastCGI_cache is a caching module for Nginx that enables static web pages from the Nginx level, effectively improving the concurrency of websites, reducing PHP runtime and request response time, and greatly improving page load speed.

Fastcgi_cache can provide cached content directly at the nginx level without involving PHP or WordPress, speeding up the process better than Wp Rocket. In contrast the cache plugin still needs to be handled by PHP at the application level for each request, which consumes more CPU.

Some members of the group said that they installed and compared Nginx servers with fastcgi_cache caching enabled to be faster than Litespeed servers. However, the caching plugin can still come with many features, such as the ability to benchmark and control the content of the cache.

Comparison of average response times of various caches ↓:

Pasted 108

 

Of course, the premise is that your server itself has sufficient performance, if only 1H1G, and then how to optimize can not significantly improve the results. Now most people build a site using the Pagoda panel, convenient and hassle-free. The following shares the Pagoda panel to open FastCGI_Cache cache method.

Note: Since FastCGI_Cache caches PHP requests, it may cause site exceptions. For example, invalid reading count, cached commenter information, cached login screen, etc. Additional code needs to be added to fix this. Novice users are not recommended to use FastCGI_Cache caching. Enabling FastCGI_Cache caching requires the use of a specialized caching plugin, not something like Wp Rocket.

 

How to enable fastcgi_cache caching in Nginx

The Pagoda panel is compiled with the Nginx ngx_cache_purge module by default, so you do not need to install it additionally.

 

Global Settings

1 Log in to the Pagoda backend, find Nginx in the software store, click the Settings button, and add the following to the configuration changes.

fastcgi_cache_path /tmp/wpcache levels=1:2 keys_zone=WORDPRESS:250m inactive=1d max_size=1G;
fastcgi_temp_path /tmp/wpcache/temp;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
# ignore all nocache declarations, avoid not caching pseudo-static, etc.
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

The screenshot after adding is as follows.

Pasted 104

 

Site Setup

Find the corresponding website in the list of websites in the Pagoda backend, click the "Settings" button, and add the following code to the configuration file. The code should be adjusted as needed, enter the web server IP (external network) address in line 43.

set $skip_cache 0;
#post accesses are not cached
if ($request_method = POST) {
set $skip_cache 1;
}
# dynamic queries are not cached
if ($query_string ! = "") {
set $skip_cache 1;
}
# backend and other specific pages are not cached (please add them for other requirements)
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-. *.php|/feed/|index.php|sitemap(_index)? .xml") {
set $skip_cache 1;
}
# does not show cache for logged in users, users who have commented
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $skip_cache 1;
}
# here please refer to your site before the configuration, especially the path of the sock, get it wrong 502! If your site uses PHP7.4, write -74.sock
location ~ [^/]\.php(/|$)
{
    try_files $uri =404;
    fastcgi_pass unix:/tmp/php-cgi-74.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
    # new cache rules
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;
    add_header X-Cache "$upstream_cache_status From $host";
    fastcgi_cache WORDPRESS;
    add_header Cache-Control max-age=0;
    add_header Nginx-Cache "$upstream_cache_status";
    add_header Last-Modified $date_gmt;
    add_header X-Frame-Options SAMEORIGIN; # allow only frames to be nested on this site
    add_header X-Content-Type-Options nosniff; # disable sniffing of file types
    add_header X-XSS-Protection "1; mode=block"; # XSS protection
    etag on;
    fastcgi_cache_valid 200 301 302 1d;
}
# cache cleanup configuration
location ~ /purge(/. *) {
allow 127.0.0.1;
allow "server extranet IP"; # quotes to be kept
deny all;
fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
}

The screenshot after adding is as follows.

Pasted 105
After you add it, save it, restart Nginx, and the cache is added.

 

Install the WordPress Clean Cache plugin

FastCGI_Cache cannot automatically clean up the site cache in a timely and accurate manner, so you need to install the supporting cache plugin to automatically control the refreshing cache. Backend search, installationNginx HelperPlugin, this plug-in specifically for fastcgi_cache cache to build, very good use.

Refer to Zhang Ge's blog setup diagram below for plugin settings.

fastcache

Choose Delete local server cache files for cleanup mode to delete cache files directly from the server and regenerate them.

My friend Nana built the site and found that the Nginx fastcgi_cache cache (404ms) is a little faster than the WP Super Cache + Memcached Object Cache cache (455ms).

 

Determining cache status

Use browser incognito mode to open the website foreground (not logged in status), press F12 to go to Developer Tools > "Network" > "Point URL" > "Select Header" to view the file header.

Pasted 106

Pasted 107

HIT stands for Hit Cache
MISS means no cache found
BYPASS stands for skip cache
EXPIRED means the cache is expired

End

Article out of date? Have a better opinion? Have a question? Please leave your comments below and we will follow up.

Recommended Articles.
Comments :

发表评论

The email address will not be disclosed, and the URL needs to be removed from https://前缀 for insertion.

Chat
  • WeChat Service
迪亚莫建站
Quick login without registration

Enter your username and password to log in

Have no account? Forgot password?