How to Switch Between Apache and Nginx on a Linux Server

October 11, 2025 / Servers, Hosting & Email

Apache and Nginx are two of the most popular web servers used on Linux systems. Apache offers flexibility and easy configuration, while Nginx provides faster performance and efficient resource usage.

This guide explains how to switch between Apache and Nginx on a Linux server using simple command-line steps.

Introduction

When handling a Linux hosting server, you may need to switch between Apache and Nginx, two of the most popular open-source web servers.

  • Apache is known for its flexibility, widespread compatibility, and easy integration with cPanel-based environments.
  • Nginx is valued for its lightweight architecture and high performance under heavy traffic.

Switching between them can help improve your website’s speed, resource efficiency, or compatibility with specific applications.

Check Which Web Server Is Currently Running

First, check which web server is currently active.

  1. Use the following command:
    sudo systemctl status apache2

    or

    sudo systemctl status nginx
  2. If one of them shows “active (running)”, that’s your current web server.

Stop and Disable the Current Web Server

To switch, you must first stop and disable the currently running one.

  1. For Apache:
    sudo systemctl stop apache2
    sudo systemctl disable apache2
  2. For Nginx:
    sudo systemctl stop nginx
    sudo systemctl disable nginx

Install the Alternative Web Server

  1. To Install Nginx (if switching from Apache):
    sudo apt install nginx -y
  2. To Install Apache (if switching from Nginx):
    sudo apt install apache2 -y

Enable and Start the New Web Server

Once installed, start and enable the service:

  1. For Nginx:
    sudo systemctl enable nginx
    sudo systemctl start nginx
  2. For Apache:
    sudo systemctl enable apache2
    sudo systemctl start apache2

Verify the Active Web Server

  1. Now, verify which web server is running after the switch, using the command below:
    sudo systemctl status nginx
    or
    sudo systemctl status apache2
  2. You can also confirm by opening your server’s IP in a browser.
    • Apache usually shows a “It works!” page.
    • Nginx shows a “Welcome to Nginx!” page.

Conclusion

This way, switching between Apache and Nginx allows administrators to optimise server performance according to their website’s needs, using Apache for robust .htaccess-based configuration and compatibility, and Nginx for lightweight, high-speed static content delivery.

Want better control over server sessions? Learn How to create/set active session in Plesk

Spread the love