This short tutorial is based on this original article at Virtualmin wiki with a few tweaks to enable us to run the latest stable version of Nginx software in Virtualmin.
Over the short few years since Nginx was first introduced, it has grown by leaps and bounds in popularity and it is currently being used by 40% of the world’s busiest websites. It is fast, stable and uses less resources compared to the Apache webserver. But we will not go into the Apache vs Nginx here …
But before you install Nginx, please be aware of the following:
- If you currently have a Virtual Server running on Apache, you can’t install Nginx because Virtualmin will only allow you to run either Apache or Nginx. You can’t run both on port 80.
- Once you’ve installed Nginx, you will need to disable Apache from the Virtualmin’s Plugin & Features page.
- Virtualmin (at this point in time) does not support Nginx as Reverse-Proxy. If you are interested in this topic (running Nginx as reverse proxy to Apache), let me know and I’ll put up a tutorial on it later.
You can install Nginx from Virtualmin’s software repository which provides an older version of the Nginx software (version 1.0.9 as of this writing – 23 Oct 2014). Most software repositories such as the CentOS repo, EPEL, Ubuntu, etc do not carry the latest version. But if you want to install the latest stable version, you need to go to the source directly and install the Nginx repository.
Goto: http://nginx.org/en/linux_packages.html#stable and download the version for your Operating System.
In our case, we will base this tutorial on CentOS 6.5.
Step 1: Download the Nginx repo and install it. Then run the ‘yum’ command to install Nginx
rpm -ivh nginx-release-rhel6*
yum install nginx -y
Step 2: Shutdown the Apache webserver & start the Nginx webserver
/sbin/service httpd stop && chkconfig httpd off
/sbin/service nginx start
Step 3: Install the Virtualmin’s Nginx plugin
yum install wbm-virtualmin-nginx wbm-virtualmin-nginx-ssl
Step 4: Login to Virtualmin and go to “System Setings” –> “Plugin & Features”
Disable the following:
- Apache Webserver
- SSL Website
- DAV login
- Webalizer Reporting
- AWstats Reporting
- Protected Directories
- Subversion repositories
Enable the following:
- Nginx Website
- Nginx SSL website
See the screenshot of the Virtualmin’s “Plugin and Features” page:
Once you’ve done this, Nginx support has been enabled in Virtualmin and you should be able to create Virtual Servers as normal.
However, do take note that when using Nginx instead of the Apache webserver, there are some limitations to consider:
- Nginx does not support CGI, so any applications or Virtualmin scripts that use CGI will not work.
- PHP can only be executed via FastCGI, and all PHP scripts run with domain owner permissions. Virtualmin will setup a PHP FastCGI server process that communicates with Nginx for each virtual server. mod_php is not supported.
- Only one PHP version (usually the highest) will be used by Nginx.
- You can only install one SSL certificate per IP address on your virtual server – even if you have a wildcard or UCC certificate. To install additional certificates, you would need to have additional IP addresses.