How to Install Nginx on Ubuntu 12.04

After struggling in Lighttpd, I’ve decided to uninstall Lighttpd, and change my web server to Nginx. Here’s how to install Nginx on Ubuntu 12.04.

sudo apt-get install nginx

Start the Nginx service:

sudo service nginx start

In some cases, you may need to reboot your system:

sudo reboot

Now, go to http://localhost/ from your browser. That’s it, Nginx has been installed.

Welcome to nginx!

Next, I’m gonna show you how to add another “path” / location / folder on your web root directory.

For example, I wanna access the /home/wks-401/public_html/ from http://localhost/public/ and enable the directory listing on it. Here’s how to add directory and enable directory listing on Nginx:

Use your favourite text editor to edit the /etc/nginx/sites-enabled/default

sudo pico /etc/nginx/sites-enabled/default

And add a new “location” section.

location /public {
	alias /home/wks-401/public_html/;
	autoindex on;
	autoindex_exact_size off;
	autoindex_localtime on;
}

Save the file, and reload the Nginx configuration.

sudo service nginx reload

Done. :mrgreen: