How to Enable FastCGI Cache in Nginx for WordPress

If you want to improve the performance of your WordPress site, you can speed up your site by enabling Nginx FastCGI Cache. In this post, How to Setup FastCGI Cache on Nginx Ubuntu 18.04 Server for WordPress? Let me know about How to setup FastCGI Cache in Nginx on Ubuntu Server for WordPress blog beginner guide 2020.

 

How to Enable FastCGI Cache in Nginx for WordPress

 

By the way, you can use WP Super Cache, W3 Total Cache Plugin to improve the speed of WordPress site, but it is better than FastCGI Cache Plugin for page caching.

 

 

Nginx FastCGI Cache is 60% faster than WordPress Cache Plugin and can handle more than 1.5 requests per second. I use the same on my site.

For example, you can see in this compare tutorial which of the FastCGI Plugin and Cache Plugins is better and which site speeds up more.

 

 

Now, let me show you an easy way to enable FastCGI cache on Nginx Server.

 

How to Enable FastCGI Cache in Nginx for WordPress

For this you need to have Nginx WordPress on Ubuntu Server, if you don’t have Ubuntu Server installed, then I will write a post about it to you soon with the help of which you can install Ubuntu Server.

 

You can then activate FASTCGI CACHE install by following the steps below.

 

Step 1: Open Nginx Configure File:

To enable FASTCGI CACHE you need to add code to the Nginx configuration file. For this, you have to access your server via PUTTY via FTP and open the Nginx configure file with this command.

 

$sudo nano /etc/nginx/sites-available/default

 

Step 2: Configure FastCGI in Nginx Block:

I’m adding my full Nginx configure file code here and highlighting the FastCGI code in red. You have to set it up in your Nginx block in the same way.

fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m;
fastcgi_cache_key “$scheme$request_method$host$request_uri”;
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
add_header X-Cache $upstream_cache_status;
server {
listen 80 default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name supportmeindia.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
include fastcgi_params;
fastcgi_cache MYAPP;
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
fastcgi_cache_valid 200 60m;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
log_not_found off;
access_log off;
allow all;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|eot|otf|ttf|woff)$ {
expires max;
log_not_found off;
}
set $no_cache 0;
if ($request_method = POST) {
set $no_cache 1;
}
if ($query_string != “”) {
set $no_cache 1;
}
if ($request_uri ~* “/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|post-sitemap.*.xml|sitemap(_index)?.xml”) {
set $no_cache 1;
}
if ($http_cookie ~* “comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in”) {
set $no_cache 1;
}
}

 

After configuring correctly, select Yes by pressing Ctrl + x and save the file.

 

Step 3: Check Configuration and Restart Nginx:

Now check the configuration test with this command and restart Nginx Server.

$sudo nginx -t
$sudo systemctl reload nginx

Congratulations! You’ve successfully enabled FastCGI Cache on successfully Nginx Server, but stop still needs to check if it’s working.

 

Step 4: Check FastCGI work or not

Now you need to check if FastCGI cache is working on your blog. Open your blog in an internet browser and check its header section. You will see this option.  “X-Cache: HIT”

 

 

If the hit header appears, it means that FastCGI is working properly on your blog. You can check the site header code on speed test tools like Pingdom, GTmetrix etc.

 

Step 5: Purging FastCGI cache

If you ever need to delete a FastCGI cache, you can login to your server with PUTTY and clear the cache from the command line below.

 

$sudo rm -r /etc/nginx/cache/*

 

This way you can easily enable FastCGI cache on Nginx Server for your WordPress website.

 

If you like this information, be sure to share it with other bloggers so that they too can use it and learn the benefits of installing it.

 

 

If you like more of my articles like this, please let me know in the comments and give your opinion

 

 

 

 

 

Spread the love

Leave a Comment