We use cookies to improve our services and provide a better experience. By continuing to use this site, you agree with our Cookies Policy.

Tutorials
More than 400 step-by-step articles to guide you through online project development.
HomeTutorialsOperating SystemsLinux

How to Install and Set Up Nginx?

Linux KVM Hosting
Linux Cloud Server
cPanel KVM
Windows Cloud Server
Brazil VPS
KVM VPS
Germany Cloud Servers
USA VPS
OpenVZ VPS
Ubuntu VPS

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.

Follow These Steps to Install Nginx

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 update
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:

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. You should see the default Nginx landing page, which should look something like this:

how-to-install-nginx-image-1

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

You 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, you have just installed Nginx and your service is now configured to start up at boot time.

USA VPS
KVM VPS
Ubuntu VPS
Windows Cloud Server
Linux KVM Hosting
Germany Cloud Servers
OpenVZ VPS
Brazil VPS
Linux Cloud Server
cPanel KVM
Rate this Tutorial:
No Comments Leave a Comment
Leave a Comment

Other (3)

Popular Keywords