Accelerate cPanel® Web Hosting with NGINX® Caching

Posted on

In web hosting, speed reigns supreme. Fast-loading pages are a priority for both users and search engines. cPanel & WHM now officially supports NGINX caching, enabling web hosts and server administrators to quickly implement server-side caching for all users. This significantly boosts web performance with minimal setup.

See NGINX caching in action by watching our recent cPanel LIVE! NGINX broadcast, featuring a configuration walkthrough and performance demo.

This article delves deeper into server-side caching, highlighting the benefits of cPanel’s NGINX caching support for web hosts and server administrators. We’ll also guide you through installation instructions and explore configuration options.

Server-Side Caching Explained

Computers serve various purposes, from website hosting to banking systems to spacecraft navigation. While applications differ, the underlying model remains the same: data retrieval from storage, processing, and result storage.

Data retrieval and processing take time, so optimizing speed is essential. We also want to avoid redundant operations. That’s where caching comes in. Caching stores data from computationally expensive processes for future reuse.

The goal of caching is to accelerate information retrieval while minimizing resource consumption. This principle is why your laptop utilizes fast RAM and a slower hard drive: RAM acts as a cache for the less expensive but slower hard drive. It’s also why browsers store static assets of visited websites instead of repeatedly downloading them. And it’s why web servers cache HTML pages in memory or on disk rather than dynamically generating them for each request.

Several caching levels are commonly employed on the internet. Here are a few examples:

  • Client-side caching refers to the various resource caches managed by web browsers and operating systems.
  • Content distribution networks (CDN) cache web page assets on geographically distributed servers, closer to users than the primary hosting server.
  • Server-side caching stores dynamically generated web pages on the server.

This article focuses on server-side website caching. Modern server-side content management systems and e-commerce platforms dynamically generate pages. When a browser requests a page, the CMS executes code and queries the database. This data is then combined with a template to create an HTML page. Dynamic pages enable personalization, but the process is resource-intensive.

A CMS like WordPress® dynamically generates pages with each request. This is necessary for pages that change frequently, such as an e-commerce cart, but inefficient for serving static content. It’s more efficient to generate the article’s HTML once and serve the same data to all users.

Server-side caching can be implemented in various ways, but one of the most effective is using a caching proxy. The proxy handles three tasks:

  1. It receives web requests and forwards them to the web server. The web server generates the page and sends it back to the proxy, which then forwards it to the browser.
  2. It stores the page received from the web server in a cache.
  3. Upon receiving a subsequent request for the same page, it retrieves the page from the cache and sends it directly to the browser, bypassing the web server.

The proxy can retrieve and return pages quickly, resulting in faster delivery and reduced server load.

Caching with NGINX

NGINX functions as a web server, reverse proxy, and HTTP cache. It can replace the Apache web server in certain situations, as described in NGINX Standalone, or it can function as a server-side reverse proxy and cache to improve the performance of dynamic websites served by Apache.

NGINX is considered a reverse proxy because it controls access to one or more web servers. Clients (web browsers) cannot connect directly to the web server but must go through NGINX. This setup offers two main advantages:

  • NGINX observes all traffic from the web server to the internet, enabling web page caching.
  • It can intercept connections and deliver cached responses, bypassing the web server completely.

Previously, deploying NGINX as a cache for sites on cPanel servers was complex. However, the NGINX Manager tool and official support for NGINX caching make it straightforward.

Server-Side Caching with cPanel and NGINX

cPanel & WHM now has a feature that simplifies the deployment of NGINX as a cache on cPanel servers. In cPanel & WHM Version 96, the NGINX Manager interface allows administrators to enable NGINX caching for all users with a single click.

NGINX Manager also offers administrators the ability to globally and individually control NGINX caching on a per-user basis.

NGINX Caching for cPanel & WHM Version 94

Users of cPanel and WHM Version 94 and other supported versions can also leverage NGINX caching. You’ll need the following to activate it:

  •  Root account access to the server.
  • Access to WHM with EasyApache 4 installed.

Select EasyApache 4 from the WHM sidebar menu. Click the Customize button in Currently Installed Packages.

Click Additional Packages and enable the switch next to NGINX.

Click Next at the bottom of the page. On the next page, scroll to the bottom and click Provision.

WHM will install and configure NGINX, replacing Apache on the default HTTP ports. It also reconfigures Apache to utilize non-standard ports, typically 81 and 444. Lastly, it activates NGINX caching for all cPanel user accounts on the server.

To configure NGINX cache settings, we provide a command-line script called ea-nginx with the same functionality as NGINX Manager. Use ea-nginx to manage NGINX users, configure user and system caches, and clear the NGNIX cache.

For example, to enable NGINX caching for a user, use the following command:

/usr/local/cpanel/scripts/ea-nginx cache username --enable

Refer to the ea-nginx documentation for further details.

Faster Websites with cPanel and NGINX Caching

If you’re considering NGINX caching for your servers, the answer is almost undoubtedly yes. It’s quick to deploy, significantly improves performance, and reduces server load. For an in-depth implementation guide and configuration details, consult the NGINX with Reverse Proxy documentation.

As always, we welcome your feedback and comments. We’re here to assist you. Connect with us on Discord, the cPanel forums, and Reddit. Be sure to follow us on Facebook, Instagram, and Twitter.

Leave a Reply

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