How to Install NGINX on cPanel With WHM’s NGINX Manager

Posted on by Devon Kauffman | Updated:
Reading Time: 6 minutes

NGINX is an open source web server designed to improve the stability, availability, and overall performance of your server. Here are some of the main features of NGINX:

  • Reverse proxying.
  • Caching.
  • Web serving.
  • Load balancing for HTTP, TCP, and UDP servers.
  • Proxy server for email (IMAP, POP3, and SMTP).
  • Web acceleration.
  • Media streaming.

This article guides you through the process of installing NGINX on your cPanel server with WHM’s NGINX Manager. 

What is NGINX Manager?

The NGINX Manager in WHM lets you install, uninstall or modify your NGINX with reverse proxy. This interface also allows you to manage the caching on your server. 

If NGINX is not installed on your server, the landing page of the NGINX Manager will let you install NGINX on your cPanel server by clicking on the Install button. In case NGINX is already installed, the interface defaults to the System Settings tab.

If your server already has the ea-nginx-standalone package installed, the interface will prompt you to install NGINX with reverse proxy caching. To do so, just click Switch to NGINX Reverse Proxy Mode, and the package will be installed.

Note:
In cPanel and WHM, NGINX with Reverse Proxy would not replace your Apache web server. It would pass dynamic content through a proxy to Apache instead.

Install NGINX on cPanel

Step 1: Install NGINX

There are 3 ways to install NGINX on cPanel. You can use any of the following methods:

  • Using WHM’s NGINX Manager interface by going to the Software section in WHM.
  • Using the EasyApache 4 interface within cPanel.
  • Running the below command on the command line as the root user.
yum install ea-nginx

Let’s focus on the NGINX Manager in WHM for now, as it might be the most user-friendly process for installing and setting up NGINX on your cPanel server.

If you search for NGINX Manager in WHM, the NGINX® Manager software will show as a result, and if you click on it, the interface will guide you through the installation process. Once you click Install, a new interface will appear, and WHM will install NGINX on your server while displaying a progress log. This process will also configure all cPanel accounts on the server to use NGINX and its caching feature by default. 

Once the installation is complete, you will see a button saying Go to NGINX Manager, and clicking it will lead you back to the interface and open the System Settings tab.

NGINX Configuration Changes

The NGINX installation process will change the server’s Apache installation to use different ports, and NGINX will proxy all requests to Apache. The process will only change the Apache ports if the Apache configuration uses the default ports (80, 443). If we install NGINX, the installation process also installs the required ea-ruby27-mod_passenger Apache module for installing or creating Ruby applications in cPanel.

Step 2: Configuring NGINX

Let’s look into some of the configuration options to customize your NGINX installation. The NGINX Manager in WHM will help you with some of the default configurations like enabling/disabling the user settings, so let’s look into that first. 

The System Settings part of the interface will let you manage your NGINX server, providing you with access to the following actions:

  • Use Caching by Default - If this is set to Enabled, this setting applies to any accounts without a caching status explicitly set. It would also make any new accounts created on the server use caching by default.
Note:
Enabling or disabling the caching status for a user account will make the system default setting no longer apply to that user.
  • Clear Cache for All Users 
  • Restart NGINX
  • Rebuild Configuration
  • Reset Users to System Default
  • Uninstall NGINX Reverse Proxy

The other section of the interface, User Settings, lets you manage user-specific NGINX settings. A table will be displayed with the user’s username and their NGINX caching status. Within this section, you can do the following:

  • Search for a specific user using the Search for account or owner box.
  • Change a user’s NGINX caching status by setting the toggle next to their username to Enabled or Disabled.
  • Change the NGINX caching status for multiple users at the same time by selecting the checkboxes next to their usernames (or selecting the checkbox on top of the table to select all users) and clicking Enable NGINX Cache or Disable NGINX Cache.
  • Clear a user’s cache by clicking Clear Cache next to the username.

Clear cache for multiple users at the same time using the checkboxes next to the usernames or the checkbox on top of the table to select all of the users by clicking Clear NGINX Cache after you have selected the users.

Note:
You can allow your cPanel users to manage their own NGINX caching status by enabling the EA4 – Allow enabling/disabling NGINX caching (requires cPanel & WHM version 100 or later) option in WHM’s Feature Manager interface (WHM » Home » Packages » Feature Manager). This will enable the NGINX Caching toggle button in the user’s cPanel interface.

Configuration Files

  • Default cPanel NGINX configuration file:/etc/nginx/conf.d/ea-nginx.conf.
  • User configuration: If you prefer customizing every server block that a user owns, you can create your own .conf file in the directory /etc/nginx/conf.d/users/username and if you wish to customize a specific server block for a specific domain create your .conf file in the directory /etc/nginx/conf.d/users/username/domainname/.
  • Global configuration: You can add any global .conf files that you create in the /etc/nginx/conf.d/ directory. To adjust every server block on your server, you can create your .conf file in the /etc/nginx/conf.d/server-includes/ directory.

Apache configuration: The NGINX installation will change the Apache port to the first available port under 1024, and this will normally be port 81. The NGINX installation will also change the Apache SSL port to the first available port under 1024, and this will normally be port 444. The installation will also add the below details to the /etc/nginx/conf.d/ea-nginx.conf file.

map $host $CPANEL_APACHE_PROXY_IP {
        default 127.0.0.1;
    }  
map $host $CPANEL_APACHE_PROXY_PORT {
        default 81;
    }
  • Custom configurations: You will need to create and include the file that ends in .conf in the appropriate location if you want to customize the server blocks for NGINX. A server block is the same as that of the virtual host in Apache. Each server block includes the .conf files in the directory /etc/nginx/conf.d/server-includes/.
  • Cloudflare Configuration: If a domain is using Cloudflare, the NGINX installation will detect it and configure the system to work properly, and the system will save the Cloudflare configuration to the location /etc/nginx/conf.d/includes-optional/cloudflare.conf.

Log Files

  • NGINX logs traffic for both www subdomains and non-www subdomains to the same location. For example, it will log requests for www.domainname.com and domainname.com to the /var/log/nginx/domains/domainname.com file.
  • The Access logs are saved to the location /var/log/nginx/access.log.
  • The SSL requests are saved to the location /var/log/nginx/domains/domainname.com-ssl_log.
  • Non-SSL requests are saved to the location /var/log/nginx/domains/domainname.com. If piped logging is disabled, both SSL and non-SSL requests will be logged to this location.
  • Bandwidth-related logs are saved to the location /var/log/nginx/domains/domainname.com-bytes_log.

Configure a User

The system will integrate NGINX into your user and domain changes and will use the /usr/local/cpanel/scripts/ea-nginx script to make these changes. It will also create your .conf file in the location /etc/nginx/conf.d/users/username.conf where username is your cPanel username.

Configure an Application

To configure applications in cPanel & WHM version 90 and later, you can use the Application Manager option in the cPanel. You can find it under the Software section in cPanel. In previous versions of cPanel & WHM, you will need to run the /usr/local/cpanel/scripts/ea-nginx script to update your configuration and then restart the server to reflect the changes.

Caching

As previously mentioned, installing NGINX on cPanel will enable caching for the domains by default, so let’s explain what that actually means:

  • NGINX will create and use a cache of the web page for the caching-enabled domain, which can substantially increase performance for the websites.
  • NGINX will proxy the request to the backend web server if the cache has expired or if it was turned off for the first request of a website.
  • The backend web server processes the request and then passes the response to NGINX.
  • NGINX then serves the response to the client. 

NGINX caches data on a per-user basis. You can find the cache file in this location: /var/cache/ea-nginx/proxy/username (‘username’ is your cPanel username). 

Step 3: Controlling NGINX Services

Run NGINX

To stop, start, or restart Nginx on cPanel, use the following script.

/usr/local/cpanel/scripts/restartsrv_nginx

It is strongly recommended that you only use the cPanel script for restarting NGINX, or you could use the Service Manager in WHM to do so (WHM » Home » Service Configuration » Service Manager).

If you’re running a CentOS 7 server, you have to use the reload option, as it ensures a graceful restart.

systemctl reload nginx.service

How to Uninstall NGINX

NGINX can easily be uninstalled from your server using the NGINX Manager in WHM. If you wish to do so, simply navigate to the System Settings section of the NGINX Manager and click Uninstall NGINX Reverse Proxy.

If you prefer to uninstall NGINX via SSH, you can use the following command.

yum erase ea-nginx

Conclusion

Improving the performance of your web server has never been easier, especially with NGINX Manager letting you install NGINX on your cPanel server with only a couple of clicks in WHM. This article should have provided you with the necessary steps to configure your own NGINX web server.

If you are interested in using NGINX on your cPanel server but don’t have one yet, contact the sales team. They can help you by providing suitable plans according to your business needs and goals. Liquid Web offers Dedicated Servers and VPS Hosting options for your next project.

Avatar for Devon Kauffman

About the Author: Devon Kauffman

Devon Kauffman is part of the Windows Support Leadership at Liquid Web. He is a proud owner of two beautiful cats and an animal and nature lover. In his free time, he enjoys playing video games, traveling, reading, watching movies and TV series (preferably horror ones), and playing with his cats.

Latest Articles

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change cPanel password from WebHost Manager (WHM)

Read Article

Change the root password in WebHost Manager (WHM)

Read Article