About Nginx
Nginx is one of the most popular web servers in the world and is also responsible for hosting several of the biggest, highest traffic sites on the internet. It is a lot more resource-friendly than Apache in many cases and can be used as a web server or a reverse proxy.
In this tutorial, we will teach you how to get Nginx installed on your Ubuntu 14.04 server.
Requirements
Before proceeding with this tutorial, you will need to have a regular, non-root user with sudo privileges configured on your server. You may learn how to do so by following steps 1-4 using our initial server setup guide for Ubuntu 14.04
Once you have an account available, log in as your non-root user to start.
Install Nginx
You have the option to install Nginx very easily since the Ubuntu team has provided an Nginx package in its default repository.
Considering that it is your first interaction using the apt packaging system in this session, update your local package index before starting so that you are equipped with the most up-to-date information. Then, you should install Nginx.
sudo apt-get update
sudo apt-get install nginx
You should be prompted for your user’s password. Enter it to verify that you would like to complete the installation. Afterwards, the software should be downloaded and automatically installed onto your server.
Check your Web Server
By default, in Ubuntu 14.04, Nginx starts immediately after it has been installed.
You may access the default Nginx landing page to verify that the software is running properly by going to your server’s domain or public IP address within your web browser.
If you do not have hold of a spare domain name, or have no use for one, you could use your server’s public IP address. If you have no knowledge of your server’s IP address, then you may obtain it in several ways from the command line.
Attempt by typing this inside your server’s command prompt.
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
You should get back one or two lines. You can then attempt each one in your web browser to check if they work.
A different way is to type it which will grant you your public IP address as seen from a different location on the internet.
curl http://icanhazip.com
Once you have your servers IP address or domain, type it into your web browser’s address bar.
http://server_domain_name_or_IP
You should see the default Nginx landing page which will have the following lines.
“Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commerical support is available at nginx.com.
Thank you for using nginx.”
Manage the Nginx Process
Now that you have your web server up and running, we will go over a couple of simple management commands.
You may stop your web server by using the following command.
sudo service nginx stop
You can also start the web server after it is stopped by typing the following.
sudo service nginx start
You can restart the service using the following.
sudo service nginx restart
You can ensure that your web server is going to restart automatically once the server is rebooted, type the below.
sudo update-rc.d nginx defaults
That is supposed to already be enabled by default, so you should see a message like this:
System start/stop links for /etc/init.d/nginx already exist.
All this means is that it was already configured, and no action was or is necessary.
Conclusion
Your web server is now installed, and you will have a lot of options for the type of content to serve and the technologies to use in order to make a better experience.