How to install and configure Nginx in cpanel

There is no native Nginx support in cpanel - only paid solutions (LiteSpeed) or abandoned plugins.

A working free option - is to put nginx as a reverse proxy in front of Apache and set up a daemon that automatically generates vhost configs when new domains are added. Below is how to do it by hand, without overpaying for ready-made modules.

1. Why not "out of the box"

cPanel is historically tailored for Apache. There are officially three options for working with nginx

OptionCostRelevanceOur verdict
Paid nginx plugin for WHMPaidSupportedJustified if you don't want to administer manually
Old community pluginFreeAbandoned, no updatesNot recommended - compatibility risks
LiteSpeedPaid (LSWS)Actively developingGood, but it's a separate ecosystem, not nginx
Manual NGINX + Apache bundle (nginx-cpl)FreeRequires independent supportOur choice for those who want control and savings

We will follow the fourth path: NGINX serves static content and SSL, Apache remains "under the hood" for processing dynamics via mod_php/suPHP - as it was configured in cpanel.

2. What should be ready in advance

Before installation:

  • Build or install NGINX with the necessary modules: ssl_module, stub_status_module, realip_module and http_v2_module.
  • Make sure that the nginx configs are in the usual location - /etc/nginx.
  • Add the service to nginx autorun: chkconfig nginx on.

3. Installing the config auto-generation daemon

This is the key logic of the solution here. The service checks every 10 seconds whether httpd.conf has changed, and when it changes, it reassembles two nginx files for each domain - for HTTP and HTTPS.

Procedure of actions:

  • Download the nginx-cpl-v3 archive and unpack the contents in /usr/share/nginx-cpl/sh-mod/.
  • Copy the nginx-cpl3 services to /etc/init.d/ and grant execution rights: chmod u+x /etc/init.d/nginx-cpl3
  • Enable autorun: chkconfig nginx-cpl3 on.
  • Control the daemon using standard commands: service nginx-cpl3 start|stop|status.
  • For convenience, write an alias in /root/.bashrc, to force config updates with a single gen-vhosts-consol command instead of the full path to the PHP script.

4. Setting up config.php - key parameters

This is what determines how they "negotiate" with each other over sockets

ParameterAssignment
APACHE_PORT_HTTPS / APACHE_PORT_HTTPInternal ports (for example, 1443/8080), hidden from the outside world
APACHE_CONFPath to httpd.conf, which the daemon parses
NGINX_PORT_HTTPS / NGINX_PORT_HTTPStandard external ports (443/80), which nginx will accept
NGINX_CONFNginx directory for generated domain vhost files (/etc/nginx/vhosts/)
CPL_BASEDaemon working directory - service files and logs

Important nuance: the generated nginx settings specify paths to the proxy and microcache inc files (/etc/nginx/proxy/).

If you don't need separate nginx settings for this, create empty proxy.inc and microcache.inc stubs, otherwise NGINX will refuse to start due to missing files.

5. The final step is to switch to WHM

  • Start the background process and make sure that nginx domain configs are available in /etc/nginx/vhosts/.
  • In WHM: Home - Server Configuration - Tweak Settings.
  • Change "Apachenon-SSL IP" to 8080, "ApacheSSL" to 1443.
  • Start the NGINX service.
  • Be sure to close ports 8080 and 1443 from external access with a firewall, otherwise Apache will remain directly accessible, bypassing nginx and all its advantages (caching, protection, load balancing).

FAQ

In 90% of cases, this means that nginx cannot reach the internal ports.

Check:

  • If the Indian is really listening to ports 8080/1443 (netstat -tulpn command | grep httpd).
  • Do these values match APACHE_PORT_HTTP/APACHE_PORT_HTTPS in config.php.
  • Is SELinux or the local firewall blocking the connection between Nginx and Indian on the loopback interface.

No, that's the point - it checks httpd.conf itself every 10 seconds and updates the settings. A manual call (gen-vhosts-consol) is only needed to force the re-creation of files, for example, after manual editing or failure.

Result

Such a bundle provides the same thing as paid solutions: nginx holds the front, returns static faster and holds more connections, and the Indian calmly works in the background with the usual cpanel PHP mechanisms.

The only price is independent support for nginx services and settings, but for a provider or an administrator with hands, this is a reasonable compromise between cost and control.