Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. It is more resource-friendly than Apache in most cases and can be used as a web server or a reverse proxy.
In this guide, we’ll discuss how to get Nginx installed on your Ubuntu 14.04 server.
Before you begin this guide, you should have a regular, non-root user with sudo
privileges configured on your server. You can learn how to configure a regular user account by following steps 1-4 in our initial server setup guide for Ubuntu 14.04.
When you have an account available, log in as your non-root user to begin.
We can install Nginx easily because the Ubuntu team provides an Nginx package in its default repositories.
Since this is our first interaction with the apt
packaging system in this session, we should update our local package index before we begin so that we are using the most up-to-date information. Afterwards, we will install nginx
:
sudo apt-get update
sudo apt-get install nginx
You will probably be prompted for your user’s password. Enter it to confirm that you wish to complete the installation. The appropriate software will be downloaded to your server and then automatically installed.
In Ubuntu 14.04, by default, Nginx automatically starts when it is installed.
You can access the default Nginx landing page to confirm that the software is running properly by visiting your server’s domain name or public IP address in your web browser.
If you do not have a domain name set up for your server, you can learn how to set up a domain with DigitalOcean here.
If you do not have a spare domain name, or have no need for one, you can use your server’s public IP address. If you do not know your server’s IP address, you can get it a few different ways from the command line.
Try typing this at your server’s command prompt:
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'
You will get back one or two lines. You can try each in your web browser to see if they work.
An alternative is typing this, which should give you your public IP address as seen from another location on the internet:
curl http://icanhazip.com
When you have your servers IP address or domain, enter it into your browser’s address bar:
<pre> http://<span class=“highlight”>server_domain_name_or_IP</span> </pre>
You should see the default Nginx landing page, which should look something like this:
This is the default page included with Nginx to show you that the server is installed correctly.
Now that you have your web server up and running, we can go over some basic management commands.
To stop your web server, you can type:
sudo service nginx stop
To start the web server when it is stopped, type:
sudo service nginx start
To stop and then start the service again, type:
sudo service nginx restart
We can make sure that our web server will restart automatically when the server is rebooted by typing:
sudo update-rc.d nginx defaults
This should already be enabled by default, so you may see a message like this:
System start/stop links for /etc/init.d/nginx already exist.
This just means that it was already configured correctly and that no action was necessary. Either way, your Nginx service is now configured to start up at boot time.
Now that you have your web server installed, you have many options for the type of content to serve and the technologies you want to use to create a richer experience.
Learn how to use Nginx server blocks here. If you’d like to build out a more complete application stack, check out this article on how to configure a LEMP stack on Ubuntu 14.04.
<div class=“author”>By Justin Ellingwood</div>
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi Justin, Thanks for the tutorials. I’m currently looking for a tutorial for installing the latest stable version of nginx on 14.04 using PPA release. Im not sure if any steps have changed since last tutorial here; https://www.digitalocean.com/community/articles/how-to-install-the-latest-version-of-nginx-on-ubuntu-12-10
@desiredpersona: The PPA used in that tutorial also provides packages for use on 14.04. So, you shouldn’t have any issues using it.
Andrew SB: Thanks
Pardon my newbie question, but which server should I choose - Apache or nginx? Or what considerations should I make to chose one?
Or, given that my droplet is mainly a playground for micro-web-apps and speed is not an issue, should i even bother? =)
@kibostoz: There are pros and cons to both Apache or nginx. While I’m partial to nginx, I generally tell people to use the one they’re most comfortable with. Though for your particular case, it sounds like nginx is probably the way to go. If you’re just using the web server as a proxy in front of an app listening on some other port, Nginx is a great choice. It’s what it was originally designed to do.
@astarr: Thank you! I guess, I’ll give it a shot then!
I switched to using Nginx for all of my servers a few years ago and it is VERY good! The clean configuration syntax is a joy to work with. It’s like switching from using XML to JSON as an data interchange format :-)
Switching from XML to JSON is a great comparison!
$ nginx -V
This installs nginx 1.4.6
Latest stable version is 1.6 as of this writing. Can I get this on my ubuntu 14.04 without compiling? As in just upgrade to it?
@SaM5246: See How To Install The Latest Version Of Nginx On Ubuntu 12.10. It should work fine on any version of Ubuntu.