On a cPanel & WHM server you do not install Nginx by hand. EasyApache 4 ships a package called ea-nginx, and it is a managed integration: it takes ports 80 and 443, moves Apache onto internal ports, generates one Nginx server block per cPanel account out of cPanel’s own userdata, and rewrites those files whenever a domain, a document root or a certificate changes. Apache does not leave — it still owns PHP handlers and .htaccess semantics for everything Nginx proxies through. The single operational fact that matters more than any tuning you will do afterwards is that the generated configuration is disposable: a rebuild overwrites it without asking, so every customisation has to live in an include directory instead. This guide covers enabling ea-nginx, drawing the line between the two tiers correctly, and the two failures that catch nearly everyone — Apache logging 127.0.0.1 for every visitor, and a Cloudflare hop that buries the real client IP one position deeper in X-Forwarded-For.
What you’ll accomplish
- Enable the cPanel-managed Nginx tier from WHM or the command line, and confirm both tiers are listening where they should be.
- Know precisely which requests Nginx answers itself and which ones reach Apache — and therefore which
.htaccessrules still apply. - Restore the real client IP end to end, so logs, ModSecurity, country rules and WordPress login limiters stop seeing loopback.
- Put customisations somewhere that survives the next regeneration instead of somewhere that silently disappears.
- Roll the whole thing back to Apache-on-80 in a few minutes if it does not suit the workload.
Prerequisites
- cPanel & WHM with EasyApache 4 on a supported RHEL-family distribution (AlmaLinux, Rocky, CloudLinux).
ea-nginxis an EA4 package; it does not exist on a hand-built Apache. - Root shell access, plus WHM access for the graphical path. Both are used below.
- No other service on ports 80 and 443. If LiteSpeed Web Server is running as the Apache drop-in, it already owns those ports and the two will collide.
- A maintenance window. Enabling
ea-nginxmoves Apache’s listeners, which restarts Apache and briefly interrupts HTTP. - Version differences are real. cPanel has reorganised the Nginx include layout and the Nginx Manager screen more than once. Where this guide gives a discovery command instead of a literal path, run the discovery command — the answer for your build is authoritative and this page is not. Check the cPanel documentation for your version.
How it works
Before ea-nginx, a browser connected straight to Apache. After, there is one more hop, and that hop is where both the performance gain and every subtle bug come from.
Nginx terminates the client connection. It handles TLS, keepalive and slow clients cheaply, answers cache hits and whichever static paths its generated config claims, and proxies everything else to Apache over loopback. Apache keeps the parts that are genuinely Apache’s: the PHP handler configuration cPanel manages per account, .htaccess processing, ModSecurity, and the Include Editor customisations you already have.
The consequence people miss is arithmetic. Apache’s peer address is now 127.0.0.1 on every single request. Nothing that reads REMOTE_ADDR — not your log analytics, not a country-blocking rule, not a WordPress login-limiter plugin — can tell two visitors apart unless mod_remoteip is configured to read the forwarded header and trust the proxy that set it. ea-nginx handles this for the plain Nginx-to-Apache hop. It cannot know about hops in front of your server.
The second thing to internalise is which files are yours.
Step-by-step
-
Install the package. From WHM, go to Software, then EasyApache 4, customise the current profile, and select
ea-nginxunder Additional Packages before provisioning. From the shell it is a normal package install:dnf install ea-nginxSuccess looks like the package installing along with its dependencies, and the
nginxservice being enabled. The installer also rewrites Apache’s listening ports as part of the process. -
Confirm both tiers are where you expect. This is the check that tells you the integration actually took effect:
ss -tlnp | grep -E ':(80|443|8080|8443) 'Expect
nginxon0.0.0.0:80and0.0.0.0:443, andhttpdon the internal pair:LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=1841,fd=6)) LISTEN 0 511 0.0.0.0:443 0.0.0.0:* users:(("nginx",pid=1841,fd=8)) LISTEN 0 511 0.0.0.0:8080 0.0.0.0:* users:(("httpd",pid=2033,fd=4)) LISTEN 0 511 0.0.0.0:8443 0.0.0.0:* users:(("httpd",pid=2033,fd=6))Cross-check the Apache side against its own configuration:
grep -E '^Listen' /etc/apache2/conf/httpd.confIf Apache is still on 80, the port change did not apply. Fix it in WHM’s Tweak Settings — the Apache non-SSL and SSL port values live there — then rebuild and restart Apache rather than editing
httpd.conf, which cPanel regenerates too. -
Read the generated configuration before changing anything. One file per cPanel account is generated under the users directory:
ls /etc/nginx/conf.d/ /etc/nginx/conf.d/users/ | head -40Open one. Note the header comment marking it as generated, the
proxy_passto the Apache port, the certificate paths, and — importantly — thelocationblocks. Those blocks tell you which requests Nginx answers from disk and never shows Apache:grep -n 'location\|proxy_pass\|ssl_certificate' /etc/nginx/conf.d/users/<user>.confAnything Nginx answers directly does not run through
.htaccess. Directory Privacy, hotlink protection anddenyrules on those paths stop applying the moment Nginx starts serving them itself. That is not a bug; it is the trade you accepted. -
Put customisations in an include directory. The include layout has changed between cPanel versions, so list what your build actually ships rather than trusting a path from a forum post:
ls -d /etc/nginx/conf.d/*/Server-wide snippets go in your own
.conffile directly under/etc/nginx/conf.d/. Per-account and per-domain snippets go in the include directories the listing above reveals. Never edit a generated file to make a change stick — the next regeneration will discard it, usually days later, when nobody connects the outage to the edit. -
Verify client-IP restoration on the Apache side. Confirm the module is loaded and the directives exist:
httpd -M 2>/dev/null | grep -i remoteip grep -ril remoteip /etc/apache2/conf.d/You want
remoteip_module (shared)and a configuration fragment containingRemoteIPHeader X-Forwarded-Forplus aRemoteIPInternalProxyentry for loopback. Apache’s mod_remoteip documentation explains the trust walk: Apache reads the header right to left and stops at the first address that is not a trusted proxy. -
Add the upstream hops if anything sits in front. With Cloudflare in the path there are two proxies, not one. Cloudflare sets the visitor address, Nginx appends the address it saw — a Cloudflare edge IP — and Apache walks the list from the right. Loopback is trusted, so it moves left one step and finds the Cloudflare edge IP. If that range is not also trusted, Apache stops there and every visitor logs as Cloudflare. The fix is to trust Cloudflare’s published ranges on both tiers; the full procedure, including the
CF-Connecting-IPalternative, is in restoring the real client IP behind Cloudflare. -
Regenerate, test, reload. After any change, rebuild the generated configuration and validate before touching the running service:
/usr/local/cpanel/scripts/ea-nginx config --all nginx -tA passing test prints two lines:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successfulOnly then reload:
systemctl reload nginxThe same script carries the cache subcommands — enabling, disabling and clearing caching for a single account. Run
/usr/local/cpanel/scripts/ea-nginx --helpto see the exact names on your version rather than copying them from elsewhere; they have changed. The graphical equivalent is WHM’s Nginx Manager, which exposes global and per-account caching.
Validate it works
Confirm the front tier is answering and terminating TLS:
curl -sI https://example.com/ | grep -iE '^server:|^http/'
Expect an HTTP/2 200 or HTTP/1.1 200 OK and a Server: nginx header.
Now prove the client IP survives both hops. Drop a temporary file in the account’s document root:
<?php
echo $_SERVER['REMOTE_ADDR'], "\n";
echo ($_SERVER['HTTP_X_FORWARDED_FOR'] ?? '(none)'), "\n";
Request it from a machine outside the server:
curl -s https://example.com/whoami.php
The first line must be your public address. If it prints 127.0.0.1, mod_remoteip is not doing its job. If it prints a Cloudflare address, the upstream range is untrusted. The second line shows the chain Apache was handed, which tells you how many hops it had to walk. Delete the file when you are done.
Finally, confirm caching behaviour without relying on a response header that may not exist on your version. Request a cacheable page twice and watch whether the second request reaches Apache at all:
tail -f /etc/apache2/logs/domlogs/example.com
A cache hit produces no new Apache log line. A miss produces one. That test works regardless of how your build labels its cache.
Troubleshooting
Every visitor logs as 127.0.0.1. mod_remoteip is missing, not loaded, or has no RemoteIPInternalProxy covering loopback. Confirm with httpd -M. The downstream damage is broader than logs: ModSecurity rate rules never trigger, geo-restrictions apply the server’s own country to everyone, and WordPress login limiters either lock out every visitor at once or nobody at all.
Everyone logs as a Cloudflare address. The trust walk stopped at the first untrusted hop. Add Cloudflare’s published ranges as trusted proxies on the Apache side, and configure the real-IP module on the Nginx side so the address Nginx appends is already the visitor’s.
A change you made last month has reverted. You edited a generated file. Something triggered a regeneration — an added subdomain, a document-root change, an AutoSSL renewal, a manual ea-nginx config run. Move the change into an include directory and re-apply it.
A renewed certificate is not being served. Nginx holds the certificate now, so an AutoSSL renewal only reaches visitors once the account’s server block is regenerated and Nginx reloads. The signature is distinctive: a browser sees an expired certificate while openssl s_client -connect 127.0.0.1:8443 against Apache shows the new one. Regenerate and reload. If AutoSSL is failing outright, check that nothing in your custom includes intercepts /.well-known/acme-challenge/ before the generated rules handle it.
Logged-in users see another user’s page, or a cart empties itself. A cached response is being served to a request that should have bypassed the cache. The shipped cache configuration bypasses on session and login cookies, but the cookie names are version-specific and a caching plugin inside WordPress can add its own layer on top. Read the cache rules in the generated config, and pick one cache: either the Nginx tier or the plugin, not both fighting over the same URLs.
When this is the wrong approach
ea-nginx earns its place on servers with many concurrent, mostly-anonymous connections — content sites, high keepalive counts, TLS-heavy traffic. It earns very little on a box running a handful of low-traffic accounts, where you have added a second daemon, a second log location and a second failure mode for no measurable gain. The honest case-by-case assessment is in when Nginx in front of Apache actually makes sense.
It is also the wrong answer if your problem is PHP execution time. A reverse proxy does nothing for a slow query or an unindexed table; it only makes the connection handling in front of that work cheaper. And if you were considering replacing Apache rather than fronting it, LiteSpeed Web Server is a different decision with different trade-offs — it reads .htaccess natively, which ea-nginx does not need to because Apache is still there.
Rolling back is quick if it does not suit you. Stop Nginx, restore Apache’s ports to 80 and 443 in WHM’s Tweak Settings, rebuild and restart Apache, then remove the package once you are satisfied:
systemctl stop nginx
/scripts/rebuildhttpdconf
/scripts/restartsrv_httpd
Confirm with the same ss -tlnp check before removing ea-nginx for good.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.