How to Install and Set Up Nginx?
Before you begin this guide, you should have a regular, non-root user with
sudo privileges configured on your server.
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 your first interaction with the
apt packaging system in this session, you need to update your local package index before you begin so that your operating system is using the most up-to-date information. Afterwards, you will install
nginx using the following commands:
sudo apt-get install nginx
You will 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 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:
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:
When you have your servers IP address or domain, enter it into your browser’s address bar. 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:
To start the web server when it is stopped, type:
To stop and then start the service again, type:
You can make sure that our web server will restart automatically when the server is rebooted by typing:
This should already be enabled by default, so you may see a message like this:
This just means that it was already configured correctly and that no action was necessary. Either way, you have just installed Nginx and your service is now configured to start up at boot time.