How To Install nginx on Ubuntu / Virtualmin

Nginx is a lightweight webserver that supports most of the functionality of Apache, but is faster and uses less memory. It is suited to websites that have a large amount of static content, or virtual machines with limited memory. For more information, see http://wiki.nginx.org/Main

Set Up

The steps in this tutorial require the user to have root privileges. You can see how to set that up in the Initial Server Setup Tutorial in steps 3 and 4.

Step One—Install nginx


To install nginx, open terminal and type in:

sudo apt-get install nginx

When prompted, say yes. nginx is now installed on your virtual private server.

Step Two—Start nginx


nginx does not start on its own. To get nginx running on your VPS, type:

sudo service nginx start

 

Step Three—RESULTS: Confirm That nginx Has Started

You can confirm that nginx has been installed as your web server by directing your browser to your IP address.

**You can run the following command to reveal your virtual server’s IP address.

ifconfig eth0 | grep inet | awk '{ print $2 }'

When you visit your IP address page in your browser, you will see the words, “Welcome to nginx”

You can see a screenshot of the utilitarian nginx welcome page here

To ensure that nginx will be up after reboots, it’s best to add it to the startup.

Type this command into terminal:

update-rc.d nginx defaults

You may see a message like:

System start/stop links for /etc/init.d/nginx already exist.

If that is the case, then nginx is set up to run on startup, and you are all set.

 

Installing Nginx Support on Virtualmin

Switching a system from the Apache webserver (installed by default by Virtualmin) to Nginx should only be done if no virtual servers with websites have been created yet. Ideally the change should be done on a freshly installed system, running RHEL 6.0, CentOS 6.0 or Debian 6.0 or later. Virtualmin version 3.89 or above is also required.

The steps to remove Apache and install Nginx are :

  1. Shut down Apache with the command /etc/init.d/httpd stop ; service httpd off (on RHEL or CentOS), or /etc/init.d/apache2 stop ; update-rc.d apache2 remove (on Debian).
  2. Install Nginx with the command yum install nginx (on RHEL or CentOS) or apt-get install nginx (on Debian).
  3. Start the Nginx webserver with the command /etc/init.d/nginx start
  4. Install Virtualmin’s Nginx plugin with the command yum install wbm-virtualmin-nginx wbm-virtualmin-nginx-ssl (on RHEL or CentOS) or apt-get install webmin-virtualmin-nginx webmin-virtualmin-nginx-ssl (on Debian).

Once this is done, you can configure Virtualmin to use it as follows :

  1. Login to Virtualmin as root, and go to Webmin -> Servers -> Nginx Webserver and make sure that Nginx and its configuration files are found.
  2. If not, click on the Module Config link and set the config and command paths correctly.
  3. Return to Virtualmin, and go to System Settings -> Features and Plugins.
  4. Un-check the “Apache website” , “SSL website” and “DAV Login”, “Mailman”, “Protected web directories”, “AWstats reporting” and “Subversion repositories” features.
  5. Check the “Nginx website” and “Nginx SSL website” features, then click “Save”.
  6. If Virtualmin reports that any other features cannot be used without Apache, go back and de-select them too.
  7. Go to the System Information page and click Refresh system information in the top right.
  8. Verify that Nginx is shown as running in the “Status” section.

Using Nginx

Once Nginx support has been configured, you should be able to create virtual servers just as you would with Apache. However, on the Create Virtual Server page you will need to select Enable Nginx website? in the Enabled features section, instead of Enable Apache.

When creating a domain from the command-line API, you will need to use the --virtualmin-nginx flag instead of --web . For SSL websites, you will need to use --virtualmin-nginx-ssl instead of --ssl .

Similarly, when creating a domain via the remote API, you will need to use the virtualmin-nginx= parameter instead of web= .

Limitations of Nginx

Nginx as configured by Virtualmin lacks some features of Apache, such as :

  • Only one virtual server can have SSL enabled per IP address, even if a wildcard or UCC certificate would potentially allow multiple SSL sites to share the same IP.
  • Nginx does not support CGI, so any applications or Virtualmin scripts that use CGI will not work. Virtualmin should prevent the installation of scripts that require CGI, mod_perl or Apache-specific features.
  • PHP can only be executed via FastCGI, and all PHP scripts run with domain owner permissions. Execution via CGI or mod_php is not supported. For PHP to work, Virtualmin will setup a PHP FastCGI server process that Nginx communicates with for each virtual server.
  • Only one PHP version is supported, and Virtualmin will pick the highest version available on the system. This typically means that PHP v4 scripts cannot be run.

See More

Once you have installed nginx on your virtual private server, you can do a variety of things on your server such as Set Up Virtual Hosts or Create an SSL certificate for your site

Be Sociable, Share!

Related Posts

  • Installing Ubuntu 12.04 LTS on a XenServer VM The following steps can be taken to install Ubuntu 12.04 LTS on a VM running on XenServer 6. Unfortunately there is no standard template for Ubuntu 12.04 (at least in XenServer 6.0.2 […]
  • Create swap partition on Ubuntu To create a swap partition after an Ubuntu installation create an empty partition that should have no holes. You can then format this partition with sudo mkswap /dev/sdx replacing […]
  • Install PHP 5.4 as standalone PHP 5.4 is not packaged on most Linux distributions so it may be easiest to install it from source. On Debian-based Linux systems, you can use the following commands to install PHP 5.4 in […]
This entry was posted in Linux and tagged , , . Bookmark the permalink.

3 Responses to How To Install nginx on Ubuntu / Virtualmin

  1. Delores says:

    That is a really good tip especially to those fresh to the blogosphere.
    Short but very precise info… Thanks for sharing this one.
    A must read post!

  2. go!! says:

    Hi there, after reading this awesome paragraph i am also glad
    to share my know-how here with colleagues.

  3. Sammy says:

    I see you share interesting content here, you can earn some additional money, your website has huge potential, for
    the monetizing method, just search in google
    – K2 advices how to monetize a website

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>