Nginx – Installation on Ubuntu Precise

I have heard Nginx for several years and finally i got the motive to start playing with it. Here the steps to install Nginx on Ubuntu 12.04.01 LTS server (Ubuntu Precise).

1. Update the repositories with the root privilege.

apt-get update


2. Install Nginx.

apt-get install nginx


3. Unlike Apache, the default Nginx webroot is located @ /usr/share/nginx/www. I would like to move the webroot directory to /srv/www.

cd /srv
mkdir www
chown -R www-data:www-data /srv/www
chmod -R 775 /srv/www


4. The www-data user and group are automatically created after the Nginx installation. Next, we go to /etc/nginx where you could find the nginx.conf. Like Apache, Nginx also has the sites-available and sites-enabled folders for managing the VirtualHost.

5. Update the root and server_name settings in /etc/nginx/sites-avaiable/default as follow.

6. Create the /srv/www/index.html.

<h1>Hello Nginx! - <a href="">Eureka!</a></h1>


7. Reload the Nginx config using the following command.

/etc/init.d/nginx reload


8. Open your server URL and check it out.

9. Nginx does not come with commands like a2ensite and a2dissite in Apache for managing VirtualHost. If you want to add new VirtualHost, you need to create the symbolic link in the /etc/nginx/sites-enabled folder.

ln -s /etc/nginx/sites-available/<virtualhost-file> /etc/nginx/sites-enabled


10. Reload the Nginx for the new settings to take effect. On the other hand if u want to remove the VirtualHost, just remove the symbolic link in /etc/nginx/sites-enabled.

Done =)

Next: Nginx + PHP-FPM on Ubuntu Precise


3 thoughts on “Nginx – Installation on Ubuntu Precise”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.