Call Us: 992 9441 754

Run NginX with Apache on cPanel/WHM: Quick Guide [Closed]

< All Topics

Run NginX with Apache on cPanel/WHM: Quick Guide [Closed]

Running Nginx alongside Apache on a server managed by cPanel/WHM can be a bit challenging but offers performance and flexibility benefits. Here’s a detailed guide on how to achieve this setup, leveraging the strengths of both web servers and the management capabilities of cPanel/WHM.

Understanding the Setup

  • Apache: The default web server used by cPanel/WHM, known for its flexibility and extensive module support.
  • Nginx: A high-performance web server and reverse proxy server, often used for handling static files and acting as a load balancer.

In this setup, Nginx typically acts as a reverse proxy in front of Apache, handling incoming requests and passing them to Apache for processing.

Prerequisites

  1. Root Access: You need root access to the server to install and configure both web servers.
  2. Backup: Always back up your server before making significant changes.
  3. cPanel/WHM: Ensure you have the latest version of cPanel/WHM.

Step-by-Step Guide

1. Install Nginx

cPanel doesn’t natively support Nginx as a reverse proxy, but you can use third-party plugins or manual installation.

a. Using a Plugin

One of the popular plugins for integrating Nginx with cPanel/WHM is Nginx Admin or Engintron.

Install Engintron (popular and well-maintained):

  1. SSH into your server as the root user.
  2. Execute the following commands:

This script will install Nginx and integrate it with cPanel/WHM.

b. Manual Installation

For manual installation, follow these steps:

  1. Add the EPEL repository (if not already present):
  1. Install Nginx:
  1. Start Nginx and enable it to start at boot:

2. Configure Nginx as a Reverse Proxy

After installing Nginx, configure it to act as a reverse proxy for Apache.

  1. Edit the Nginx configuration file:
  1. Add or modify the following configuration to make Nginx proxy requests to Apache (usually running on port 8080 or 81 with Nginx in front):
  1. Test Nginx configuration:
  1. Restart Nginx to apply the changes:

3. Adjust Apache to Work with Nginx

Ensure Apache listens on a different port since Nginx will be handling port 80 (HTTP) and possibly 443 (HTTPS).

  1. Edit the Apache configuration file:
  1. Change the listening port to 8080 or another unused port:
  1. Restart Apache to apply the changes:

4. Configure cPanel/WHM to Work with Nginx

To make sure cPanel/WHM can manage sites and handle the new Nginx setup:

  1. Enable proxying support in cPanel/WHM:
  • Log in to WHM as root.
  • Navigate to Home > Service Configuration > Apache Configuration > Include Editor.
  • Under Pre VirtualHost Include, add:
  1. Restart Apache again to apply changes from WHM:

5. Configure SSL

Handling SSL with Nginx as the frontend requires configuring SSL certificates within Nginx.

  1. Install SSL certificates in Nginx:
  • Obtain SSL certificates for your domain.
  • Edit your Nginx configuration to include the SSL details:
  1. Test Nginx configuration again:
  1. Restart Nginx:

6. Manage SSL Certificates with cPanel

If using cPanel’s AutoSSL or another method for managing SSL certificates:

  • Ensure Nginx is configured to use the same certificate files that cPanel generates and renews.
  • You might need to symlink or update Nginx configurations to point to the cPanel managed certificate locations.

7. Testing and Validation

  1. Check the website to ensure it loads correctly over HTTP and HTTPS.
  2. Use tools like SSL Labs to verify SSL configurations.
  3. Monitor logs for any errors or issues:

Summary

Running Nginx with Apache on a server managed by cPanel/WHM can enhance performance and scalability. By configuring Nginx as a reverse proxy, you can leverage its speed and efficiency while still using Apache’s robust features and cPanel’s management tools. This setup requires careful configuration and testing to ensure all services work harmoniously.


Note: Using third-party plugins or making significant manual changes can sometimes affect cPanel/WHM updates and operations. Always keep a backup and be cautious with updates.

Categories

Recent Comments

No comments to show.