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

    • How to Install cPanel on Your Server or VPS: Updated Guide by Distribution

      cPanel & WHM is the most widely used control panel in the web hosting industry. If you have a dedicated server or VPS with Webzi (or any other provider), this guide shows you how to install cPanel from scratch on the currently supported operating ...
    • How to Manually Move a cPanel Account to Another Partition

      cPanel includes a native feature called rearrange that allows moving accounts between partitions from WHM. However, this process requires enough free space on the source partition to create a temporary copy, and when the partition is nearly full, the ...
    • Where Are NGINX Logs Stored? – Location & Useful Commands

      NGINX caching is highly recommended to make more effective use of server resources. It does not have a negative impact on website performance, as the .htaccess file continues to work correctly. NGINX Logs per Domain Logs are stored per domain in ...
    • 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 ...
    • Configure RAID Failure Notifications with mdadm

      A RAID array (Redundant Array of Independent Disks) is commonly used to improve data reliability and availability, as data is distributed across multiple disks (depending on the type of array). It is crucial to be notified immediately if one of the ...