How to install and configure Nginx as a reverse proxy in cPanel/WHM

How to install and configure Nginx as a reverse proxy in cPanel/WHM 🚀

What is Nginx and why use it with cPanel?

Nginx is a high-performance web server that can function as a reverse proxy in front of Apache on cPanel servers. This configuration allows Nginx to handle static files (images, CSS, JavaScript) while Apache processes dynamic content (PHP), leveraging the strengths of both servers.

Prerequisites

  • Server with cPanel/WHM and root access
  • EasyApache 4 installed
  • At least 2GB of available RAM
  • 10GB of free space in /var for cache

Step-by-step installation

Step 1: Access EasyApache 4

  1. Log in to WHM as root
  2. Navigate to Software → EasyApache 4
  3. Click "Customize" on your current profile

Step 2: Install Nginx packages

In the "Additional Packages" tab, search for and install:

  1. ea-nginx - The base Nginx server
  2. ea-nginx-http2 - Support for HTTP/2 protocol
  3. ea-nginx-gzip - Gzip compression to reduce transfer size

Click "Next" then "Provision" to apply changes. The process will take 5-10 minutes.

EA-Nginx default configuration

Ports used

EA-Nginx automatically configures the following ports:

 
json
{
"apache_port": "81",
"apache_port_ip": "127.0.0.1",
"apache_ssl_port": "444",
"apache_ssl_port_ip": "127.0.0.1"
}
  • Nginx listens on ports 80 (HTTP) and 443 (HTTPS)
  • Apache moves to ports 81 and 444 internally

Default cache configuration

nginx
proxy_cache_valid 200 301 302 60m;  # Successful responses: 60 minutes
proxy_cache_valid 404 1m; # 404 errors: 1 minute

Cache files are stored in /var/cache/ea-nginx/proxy/

Configuration file locations

  • Global configuration: /etc/nginx/nginx.conf
  • Per-user configuration: /etc/nginx/conf.d/users/[username].conf
  • Templates: /etc/nginx/ea-nginx/
  • Logs: /var/log/nginx/

Common issues and considerations

1. Dynamic content caching

Problem: The 60-minute cache can cause website changes to not appear immediately.

Symptoms:

  • Clients report their changes don't appear
  • Updated content doesn't reflect
  • Forms seem to not work correctly

Solution: Clear cache from WHM → Nginx Manager → Clear Cache

2. .htaccess compatibility

Problem: Nginx doesn't process .htaccess files. Rewrite rules, redirects, and security configurations in .htaccess won't work for static files.

Impact:

  • Custom redirects may fail
  • Directory protection may not apply
  • Custom cache rules ignored

3. Disk space usage

Cache can grow considerably:

  • 100 sites ≈ 5GB
  • 500 sites ≈ 25GB

This space is NOT counted in cPanel user quotas.

4. Duplicate logs

Logs are generated in both Nginx and Apache, duplicating space usage and complicating analysis.

How to uninstall Nginx

If you need to revert changes:

  1. In WHM → EasyApache 4 → Additional Packages
  2. Uncheck ea-nginx packages
  3. Provision to apply changes
  4. Clean residual cache:
    bash
    rm -rf /var/cache/ea-nginx/

Monitoring and maintenance

Verify HTTP/2 status

bash
curl -I --http2 -s https://your-domain.com | grep HTTP
# Should show: HTTP/2 200

Clear cache manually

bash
# For all sites
rm -rf /var/cache/ea-nginx/proxy/*

# Restart Nginx
systemctl restart nginx

When is implementing Nginx worth it?

Ideal scenarios:

  • Sites with lots of static content (images, videos)
  • Servers with high concurrency (>100 simultaneous visitors)
  • When server CPU constantly exceeds 70%
  • Well-optimized sites needing that extra speed boost
  • Sites requiring frequent changes and real-time updates
  • Applications heavily dependent on .htaccess configurations
  • When support team isn't familiar with Nginx
  • Sites with slow backends (the problem will persist)

Important considerations

Speed improvement with Nginx is most noticeable on already optimized sites. A site with slow database queries or poorly optimized code will remain slow, even with Nginx. Technology isn't a magic solution for programming issues.

The 60-minute cache can confuse users expecting immediate changes, leading to unnecessary support tickets or, worse, the perception that the hosting service has problems.


Need help with Nginx on your server?

At Webzi, we specialize in implementing and optimizing Nginx on cPanel servers. We understand both the benefits and complexities of this configuration.

If you need:

  • Evaluate if Nginx is right for your project
  • Custom implementation on your VPS or dedicated server
  • Configuration optimization for specific cases
  • Troubleshooting cache or compatibility issues

Contact us and our engineering team will evaluate your particular case. We can offer custom solutions, from special configurations to migration to servers specifically optimized for your type of application.

Remember: each project is unique and what works for one may not be ideal for another. At Webzi, we prefer to analyze each case individually to recommend the best technical solution, whether it's Nginx, LiteSpeed, or traditional Apache configuration.

    • Related Articles

    • Emails don't appear in webmail searches

      When you search for an email in Roundcube (cPanel) and it doesn't appear in the results even though it exists in your mailbox, the problem almost always stems from the server not having properly indexed the messages. For example, if you try to locate ...
    • How to delete iDrive e2 files using AWS CLI on Mac

      When you need to delete large amounts of files from an iDrive e2 bucket, doing it through the web interface can take hours or even days. The most efficient solution is to use AWS CLI from your Mac terminal, as it processes multiple files in parallel ...
    • How to Block IPs and Ranges in Imunify360: CLI & GUI Master Guide

      Imunify360 is the ultimate defense for web servers. While its automated firewall is excellent, manual intervention is sometimes necessary to stop botnets or targeted attacks. In this guide, you will learn how to manage blocks precisely using commands ...
    • How to Export and Import a MySQL Database Using Command Line

      Having an up-to-date backup of your database is essential to protect your critical information and ensure business continuity. In this tutorial, we will show you how to export a database using the command line. It is important to perform a complete ...
    • JetBackup 5: How to fix the Integrity Check error using CLI/SSH

      When JetBackup performs its automated integrity verification processes, they may sometimes complete partially due to network interruptions, timeouts, or communication issues with the remote storage destination. If you receive notifications indicating ...