Last Updated on 4 days by Sachin G

This post provides step-by-step instructions on how to install Nginx on Virtualmin as the default web server on Webmin Virtualmin. It covers downloading the Virtualmin script, running it with the --bundle LEMP option, and LEMP stack on Webmin setting up Nginx to replace Apache for enhanced performance

Apache web server is installed by default with the Virtualmin module in Webmin. Here, I have followed these steps on Ubuntu and CentOS Stream and Alma Linux Operating systems. You can check the reference link to install Virtualmin on Webmin CentOS, Red Hat, and Fedora. After that Virtualmin will be installed.

Webmin should be installed before executing this Virtualmin script.

Why Choose Nginx Over Apache in Virtualmin?

The debate between Nginx vs Apache in Virtualmin is ongoing, but for high-performance and resource-efficient web hosting, Nginx takes the lead. As a lightweight web server, Nginx handles concurrent requests more efficiently and is perfect for modern applications, especially on lower-end VPS.

In our tests on a 2GB VPS running Ubuntu 22.04, switching from Apache to Nginx reduced memory usage by nearly 30%.” — techtransit.org

Also, using Nginx with Virtualmin, though slightly more complex to configure, results in better speed and scalability.

Virtualmin and Webmin: A Powerful Duo

Virtualmin, built on top of Webmin, is an open-source hosting panel that provides a GUI to manage domains, databases, and server configurations. While Apache is the default web server, Webmin supports Nginx via the virtualmin-nginx module. The module allows seamless Nginx integration

Pre-Installation Checklist

Before starting the LEMP stack installation on Virtualmin step by step, ensure the following:

  • Ubuntu 20.04 LTS, 22.04 LTS, and 24.04 LTS on i386 and amd64
  • Rocky, Alma, and RHEL 8 and 9 on x86_64
  • Root or sudo access
  • Clean install (recommended)
  • Meets all Virtualmin requirements (Source)

Step-by-Step: Install Nginx on Virtualmin

You can use the script by following the guides like below :

Download Virtualmin Script:

wget https://software.virtualmin.com/gpl/scripts/virtualmin-install.sh

Install Virtualmin with Nginx (if not already installed)

The below script with the — bundle LEMP option will perform nginx installation with Virtualmin instead of the default Apache. and it executes with this option.

sh virtualmin-install.sh --bundle LEMP
Virtualmin Nginx

If your server is already running Apache by default, you can seamlessly switch to Nginx by removing Apache first. The steps below guide you through uninstalling Apache to prepare for Nginx installation.

Remove Apache (Optional but Recommended)

If Apache is already installed:

sudo systemctl stop apache2
sudo systemctl disable apache2
sudo apt purge apache2*

This allows a clean switch, especially important when switching Apache to Nginx on Virtualmin.

Disable the Apache web server feature

virtualmin set-global-feature --disable-feature web --disable-feature ssl

Once the Apache feature is disabled in Virtualmin. Execute the following commands to install Nginx on your server:

Install Nginx

sudo apt install webmin-virtualmin-nginx webmin-virtualmin-nginx-ssl

Then in Webmin:

  • Go to Webmin > Webmin Configuration > Webmin Modules
  • Browse local module: virtualmin-nginx

Once installed, you’ll find Manage Nginx with Webmin under Servers.


Enable Nginx in Virtualmin

There are two methods, either by interface or command line, I am giving both. Choose any one.

This ensures Nginx can serve virtual hosts properly.

Method 1:

  • Go to Virtualmin > System Settings > Features and Plugins
  • Enable the Nginx website
  • For SSL, also enable Nginx SSL website

This will configure nginx on the panel.

Method 2:

# virtualmin-config-system -i Nginx

Although it doesn’t handle PHP processing by default, you should install PHP-FPM to enable PHP support. Once installed, you may need to configure PHP-FPM to work with Nginx.i am showing below to set up php with PHP-FPM.

By following the above steps, you’ve successfully installed and configured Virtualmin with a LEMP setup.

Set up PHP with PHP-FPM

Install PHP and FPM:

sudo apt install php php-fpm

Configure Nginx for FPM (example block):

location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}

Tip: Adjust PHP version and socket path as per your system.

Test Your Setup

Deploy a basic PHP test file:

echo "" > /home/YOURDOMAIN/public_html/info.php

After configuring Virtualmin. It’s essential to test your setup to ensure everything is working correctly. Open a web browser and navigate to one of your website domains with phpinfo. One common issue users face is PHP compatibility.

Visit http://yourdomain.com/info.php to verify.

Best Settings for Nginx on Virtualmin

To optimize your server:

  • Use gzip compression
  • Set worker_processes and worker_connections Based on your CPU
  • Limit request size and buffer settings
  • Enable HTTP/2 and cache static files

These tweaks are key for server optimization with LEMP

Common Issues and Fixes

“Webmin Nginx reverse proxy not working”

  • Ensure correct proxy headers and proxy_pass format

“PHP not executing”

  • Likely PHP-FPM is misconfigured. Recheck socket path and FPM pool.

“Install Nginx Virtualmin Ubuntu 22.04 errors”

  • Use official Ubuntu repos and ensure Virtualmin scripts are updated.

FAQs

What is Virtualmin used for?

Virtualmin is a powerful web hosting control panel used to manage Linux web servers through a GUI, often replacing cPanel for open-source setups.

How to install Nginx as a web server in Virtualmin?

Install Nginx, configure it via Webmin modules, enable it for virtual hosts, and set up PHP-FPM for dynamic content.

What are the best settings for Nginx on Virtualmin?

Optimal settings include tuning worker processes, enabling caching and compression, and properly configuring PHP-FPM.

Why switch Apache to Nginx on Virtualmin?


Nginx provides better concurrency handling, lower resource usage, and faster response times than Apache.