Debian with Nginx and Virtualmin

Debian with Nginx and Virtualmin



In this post, I’m going to walk through the steps to configure Debian with Virtualmin control panel and the Nginx web server. If you are hosting multiple sites and need a fast, lightweight configuration for your VPS then this setup is ideal. As discussed in this previous article, if you are reselling hosting, I’d recommend sticking with the tried and tested combination of cPanel/Apache as it is much easier for your clients to manage.

The setup I’m building is best for webmasters or developers who are looking to host and manage their own sites and email on a low cost VPS. Nginx keeps your webserver’s memory footprint down, but makes day to day administration a fair bit trickier for end-users. Particularly because Nginx does not use htaccess files, meaning all site configuration (including redirects) need to be done in the main config file by root. However, if you are tech savvy and need to make the most of your VPS resources, this tutorial is definitely for you.

It’s best to start this installation process with a freshly installed version of Debian, if you have already configured any websites or custom settings on the server, they are likely to be lost and potentially cause problems with these instructions. To this end, I’ve just rebuilt my VPS-2 Virtual Server with a fresh template of Debian 6.0 and SSH’d in.

Installing Virtualmin


The first step is to install Virtualmin on the server. There are no special instructions here, you’ll just need to install it including all the default software it provides such as Apache. You can follow the instructions on Virtualmin’s download page – or in short, download the install script and run it.

$ wget http://software.virtualmin.com/gpl/scripts/install.sh
$ sh install.sh

Debian Coffee

This will take a little while, so it’s probably a good chance to go and make a coffee!

 

 

 

 

 

Configuring Virtualmin to use Nginx

Now that Virtualmin is installed on our VPS, we can continue with the nginx configuration by following the virtualmin nginx documentation. Below are the commands we will need to run our Debian server to first remove Apache and then install and configure nginx.

  • Stop Apache and make sure the service doesn’t start on boot
$ /etc/init.d/apache2 stop
$ update-rc.d apache2 remove
  • Install nginx and start the service
$ apt-get install nginx
$ /etc/init.d/nginx start
  • Install the Virtualmin nginx plugin
$ apt-get install webmin-virtualmin-nginx webmin-virtualmin-nginx-ssl

Once the above has been completed, we now have a server with nginx running and Apache effectively removed. Next we need to make sure that Virtualmin recognises that nginx is installed and has the right set of features ready for use.

  • Login to Virtualmin as root via the web interface (this can be found at https://your.ip.address:10000)
  • In the left hand menu, navigate to Webmin -> Servers -> Nginx Webserver
  • To make sure it is working and the configuration is correct, click the ‘Start Nginx Webserver’ button at the bottom of the screen. If you receive no errors, then Nginx has started successfully.

Now that Nginx is installed, configured and working, we will go through the Virtualmin options and disable some features which will not work with our streamlined nginx webserver.

  • In the left hand menu, navigate to Virtualmin -> System Settings -> Features and Plugins
  • You will need to disable (deselect) all the following features as they are dependent on Apache:
    • Apache website
    • SSL website
    • DAV login
    • Mailman
    • Protected web directories
    • AWstats reporting
    • Subversion repositories
  • Once all the Apache dependent features are disabled, we can enable (select) the nginx features
    • Nginx website
    • Nginx SSL website
  • Click Save on the modified list

That’s all the features sorted, we’re almost ready to create a new Nginx website, but first we’ll quickly check that Nginx is running in our newly configured Virtualmin

  • In the left hand menu, navigate to Virtualmin -> System Information and make sure ‘Nginx Webserver’ has a big tick next to it, if so, we’re ready to go.

 

Creating an Nginx site

  •  On the main Virtualmin web interface, click ‘Create Virtual Server’ from the left hand menu and enter in all the appropriate details, including domain, description and password.
  • Under ‘Enabled features’, make sure that ‘Enable Nginx website?’ is present and ticked.
  • Click the ‘Create Server’ button at the bottom of the page.

You’re done! You should now be able to navigate to the website you have just created and have the fast and lightweight Nginx webserver serving your HTML & PHP files! You can verify this by creating a new php file in the directory ‘/home/<yourdomain>/public_html/’ and adding the line:

<?php phpinfo(); ?>

The PHP Info page will show that your webserver is Nginx next to the global variable ‘_SERVER[“SERVER_SOFTWARE”]’.

 

 

 


  • Rafadev

    Hi, can we set max limit disk space and bandwith per virtual host with webmin?

    thanks

  • Great guide, works well, and speeds up website loading times by a big amount

  • Thanks for writing this post, now i can setup my first vps :))