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

Search
Enable fastcgi_cache cache
Article List
Article List

In this article, we will explain how to enable fastcgi_cache caching in Nginx via Pagoda Panel to improve the access speed of your WordPress website and reduce the burden on the server. First, we will briefly introduce the concept and role of fastcgi_cache cache. Then, we will give a detailed guide on how to configure Nginx to enable fastcgi_cache cache in Pagoda panel to set up the plugin.

 

What is fastcgi_cache cache?

fastcgi_cache is a caching mechanism provided by Nginx to improve the performance of dynamic content. It is particularly suited to applications that deal with the FastCGI protocol, such as PHP (Wordpress). fastcgi_cache enables static web pages at the system level, greatly reducing server load, concurrency, and providing increased site loading speed.

 

What are the advantages of fastcgi_cache caching?

Many people will be curious, for Wordpress, fastcgi_cache cache and regular through Wp Rocket and other plug-ins to achieve the cache what is the difference? fastcgi_cache cache is thesystem levelCaching, handled only by Nginx (PHP is not involved), so it's fast and can take a lot of concurrency. The downside is that it's not as flexible, has fewer features, and is a bit of a barrier to use, so white people rarely hear about this cache.

ByWp RocketThe caching implemented by plugins such assoftware levelThe cache is handled by PHP (Nginx is not involved), so it is slower and takes up more server resources. Advantages are controlled by plug-ins, easy to use and understand, very flexible, feature-rich, the public's favorite.

We deal with servers all the time, dealing with high concurrency and lag issues. Most of the time, memory is exhausted or CPU is overloaded because PHP is running a huge task. fastcgi_cache cache does not need to run PHP, so it takes up much less resources, greatly reducing the burden on the server.

At the same time fastcgi_cache cache is handled by Nginx, so the computation link is much shorter than the cache implemented by plugins such as Wp Rocket, and therefore faster. fastcgi_cache cache is even faster than Litespeed cache cache in some environments!

Comparison of average response times for various caches↓ (shorter is better).

Pasted 108

 

Caution.FastCGI_Cache on the server performance requirements are high, if it is 1H1G or other low configuration, and then how to optimize the effect is not obvious. If the website has more dynamic data, it is not recommended to use FastCGI_Cache cache.

Now most people use Pagoda Panel to build websites, which is convenient and time-saving. Here is how to open FastCGI_Cache cache in Pagoda Panel.

Note: Since FastCGI_Cache caches PHP requests, it may cause site exceptions. For example, read count invalidation, caching of commenter information, caching of login screen, etc. Additional code needs to be added to exclude this. Therefore, it is not recommended for newbies to use FastCGI_Cache caching.FastCGI_Cache caching requires the use of a specialized caching plugin.

 

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 Pagoda background, find Nginx in the software store, click the Settings button, and add the following contents in the "Configuration Modification":

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;
#忽略一切 nocache 申明,避免不缓存伪静态等
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 Pagoda background, click the "Settings" button, add the following code to the configuration file, and enter the IP (extranet) address of the web server in line 43.The code has to be adjusted as needed! It varies from site to site! Once again, I'm discouragedyoung white.

set $skip_cache 0;
#post 访问不缓存
if ($request_method = POST) {
	set $skip_cache 1;
}   
#动态查询不缓存
if ($query_string != "") {
	set $skip_cache 1;
}   
#后台等特定页面不缓存(其他需求请自行添加即可)
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
	set $skip_cache 1;
}   
#对登录用户、评论过的用户不展示缓存
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
	set $skip_cache 1;
}
#这里请参考你网站之前的配置,特别是sock的路径,弄错会显示502!如果你的网站使用PHP7.4,就写-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";
    #新增的缓存规则
    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; # 只允许本站用 frame 来嵌套
    add_header X-Content-Type-Options nosniff; # 禁止嗅探文件类型
    add_header X-XSS-Protection "1; mode=block"; # XSS 保护
    etag  on;
    fastcgi_cache_valid 200 301 302 1d;
}
#缓存清理配置
location ~ /purge(/.*) {
	allow 127.0.0.1;
	allow "服务器外网IP"; # 引号要保留
	deny all;
	fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1";
}

The screenshot after adding is as follows.

Pasted 105

After adding and saving, restart Nginx on it. The next step is to install the Setup Cache plugin ↓.

 

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 plugin is built specifically for fastcgi_cache caching.

The plugin settings are referenced in the image below (image source. Zhang Ge Blog).

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

Open the frontend of the website in incognito mode of your browser (not logged in), press F12 to go to Developer Tools > Network > Tap on the URL > Tap on the "Header" to view the details.

Pasted 106

Pasted 107

HIT: Cache Success
MISS: Cache failure, suggest refreshing the page 2 times to see if it has become HIT.
BYPASS: Skip Cache
EXPIRED: Cache expired

 

Advanced Tutorials

indeedThe fastcgi_cache cache can also be used with the Wp Rocket cache plugin. Using it together is more effective than using theWp Rocket is about 27% higher than the standaloneThe fastcgi_cache cache is not much different. Just install therocket-nginx, just configure it appropriately.This method has a high threshold for use, so don't use it if you don't know how.

Comments :

8 thoughts on “宝塔面板Nginx如何启用fastcgi_cache缓存? WordPress提速”

发表评论

The email address will be invisible, To put URL pls remove "https://" and "www".
Chat
  • WeChat customer service
Quick login without registration

Enter your username and password to log in