By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
Cloudbooklet Logo
  • Artificial Intelligence
  • Applications
  • Linux
Notification

Free AI Image Generator

AI Tools
Cloudbooklet AICloudbooklet AI
Search
AI Tools
  • Artificial Intelligence
  • Applications
  • Google Cloud
  • Compute Engine
  • Linux

Top Stories

Explore the latest updated news!
Character Ai Group Chat

What is Character AI Group Chat and How to Get Started?

1
Skype Voice Changer

Skype Voice Changer: How to Transform Your Voice on Skype Calls

2
Antifake

How AntiFake can Protect your Voice from Deepfake AI

1
Follow US
  • About
  • Contact
  • Disclaimer
  • Privacy Policy
Cloudbooklet © 2023 All rights reserved.

Home » Google Cloud » FastCGI Cache with Nginx for WordPress on Ubuntu 18.04 LTS

Google Cloud

FastCGI Cache with Nginx for WordPress on Ubuntu 18.04 LTS

Last updated: 2019/12/21 at 6:11 AM
By Cloudbooklet
Fastcgi Cache With Nginx For Wordpress On Ubuntu 18.04 Lts
SHARE
Readers like you help support Cloudbooklet. When you make a purchase using links on our site, we may earn an affiliate commission.

Would you like to improve your WordPress performance? Enabling FastCGI and configuring it correctly for your blog or your Woocommerce store will greatly increase your WordPress Performance.

This brief tutorial will help you setup FastCGI on Google Cloud Ubuntu 18.04

Table of Contents
PrerequisitesNginx FastCGI ConfigurationsConfigure WordPress to purge the cache

When using Nginx with FastCGI module you can increase the performance of your web application or WordPress websites, because FastCGI caches the dynamic content served by Nginx.

Prerequisites

  • Setup Compute Engine Instance and setup Google Cloud DNS
  • Have a Compute Engine running with Ubuntu, Nginx, PHP, and WordPress Installed
  • Cloud SQL configured and connected with Compute Engine

Nginx FastCGI Configurations

The first setup requires a few changes in your nginx.conf file to generate the key names and add a header for the responses, so you can easily determine whether the page is cached or not. Go ahead and edit the file and add the below directives below the GZIP section

sudo nano /etc/nginx/nginx.conf
##
# Cache Settings
##
fastcgi_cache_key "$scheme$request_method$host$request_uri";
add_header Fastcgi-Cache $upstream_cache_status;
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

Hit Ctrl+X followed by Y to save your Nginx configuration.

Now you can set up the FastCGI cache path and instruct Nginx not to cache certain pages like wp-admin, if user logged in and etc. Edit your website configuration file and add these

sudo nano /etc/nginx/sites-available/yourdomainname.com

Add this to the top of your configurations. Don’t forget to update the path and domain name with yours

fastcgi_cache_path /home/username/yourdomainname.com/cache levels=1:2 keys_zone=yyourdomainname.com:100m inactive=60m;

Now instruct Nginx not to cache the admin pages, Woocommerce dynamic pages, and others.

Add the below cache exceptions below the root path inside your server block

set $skip_cache 0;

# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
     set $skip_cache 1;
}
if ($query_string != "") {
     set $skip_cache 1;
}

if ( $cookie_woocommerce_items_in_cart = "1" ){
     set $skip_cache 1;
}

# Don't cache URIs containing the following segments
if ($request_uri ~* "/wp-admin/|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
     set $skip_cache 1;
}
if ($request_uri ~* "/(cart|checkout|my-account)/*$") {
     set $skip_cache 1;
}

# Don't use the cache for logged-in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
     set $skip_cache 1;
}

Now inside the php location block location ~ \.php$ { add these

fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache yourdomainname.com;
fastcgi_cache_valid 60m;

Hit Ctrl+X followed by Y to save the configurations and restart Nginx

sudo nginx -t

Check for the Nginx configuration success message and proceed to restart Nginx

sudo service nginx restart

Now if you visit your website and check the headers, you can see a new header with these possible values

  1. HIT – Page cached
  2. MISS – Page not cached (refreshing should cause a HIT or BYPASS)
  3. BYPASS – Page cached but not served (admin screens or when logged in or Woocommerce account pages)
  4. STALE – Page is served from cache that is stored in cache directory.

Configure WordPress to purge the cache

Finally, install a plugin to purge the cache when WordPress content changes. Install the Nginx Cache plugin.

Once installed navigate to Tools >> Nginx and define the cache path you defined earlier and enable the purge cache option and save the settings

Now your WordPress is configured to use Nginx FastCGI cache.

TAGGED: Google Cloud Platform, Nginx, Ubuntu 18.04, WordPress
Share This Article
Facebook Twitter Whatsapp Whatsapp LinkedIn Reddit Telegram Copy Link Print
Share
1 Review 1 Review
  • Avatar Of RumeshRumesh says:

    Thanks a lot for the tutorial. Exactly I was looking for!

    Reply

Leave a review Cancel reply

Your email address will not be published. Required fields are marked *

Please select a rating!

Popular

Moonvalley Ai
How to Create Stunning Videos from Text with Moonvalley AI Free Tool
Artificial Intelligence
Temu Glitch
How to Get 100% off Coupons on Temu Glitch using Tinyurl
Artificial Intelligence
Stable Video Diffusion
How to run Stable Video Diffusion img2vid- Guide
Artificial Intelligence
Azure Ai Speech
How Azure AI Speech Can Help You Create Realistic and Engaging Avatars
Artificial Intelligence
- Advertisement -

Subscribe Now

loader

Subscribe to our mailing list to receives daily updates!

Email Address*

Name

Related Stories

Uncover the stories that related to the post!
Free Linux Cloud Server
Artificial Intelligence

Top 5 Free Linux Cloud Servers to Host Your Website

Openai Reverse Proxy With Nginx
Artificial IntelligenceLinux

How to Setup OpenAI Reverse Proxy with Nginx

How To Install Git On Ubuntu 20.04
Google CloudLinux

How to Install Git on Linux

Vector Image
Data ScienceGoogle Cloud

DataStax Enhances Astra DB on Google Cloud with Vector Search Capability

Cloudbooklet Logo
  • Categories:
  • Artificial Intelligence
  • Applications
  • Google Cloud

Quick Links

  • About
  • Contact
  • Disclaimer
  • Privacy Policy
Cloudbooklet © 2023 All rights reserved.
Welcome Back!

Sign in to your account

Lost your password?