logo
. . .

How to Setup Nginx HTTP Server on Ubuntu 18.04 LTS Server #5

How To Install And Configure Nginx on Ubuntu 18.04 LTS

Step 1: Updating Ubuntu Server

sudo apt update

Step 2: Installing Nginx on Ubuntu Server

sudo apt install nginx

Step 3: Managing Nginx Web Server

— Stops the server: 

sudo systemctl stop nginx.service

— Start the server: 

sudo systemctl start nginx.service

— Restarts the server:

sudo systemctl restart nginx.service

— Reload config changes no stops: 

sudo systemctl reload nginx.service

Step 4: Configure Nginx Server

When Nginx is install on Ubuntu servers, the default document root directory is located at /var/www/html Just as with Apache2 server on Ubuntu.

The majority of Nginx configurations files are stored in /etc/nginx directory.

Two important locations you’ll spend most of your time are /etc/nginx/sites-available and /etc/nginx/sites-enabled

The sites-available directory contains all the available sites. This is the location you create new site configuration files, and sites-enabled directory contains all sites that are enabled. By default, sites are not enabled until you run commands to enable them.

The first default site configuration file is /etc/nginx/sites-available/default

Step 5: Enabling and Disabling Nginx Sites

After creating Nginx sites on Ubuntu something to remember is to always enable the sites. With Apache2, we showed you how to do that. Sites can be enabled by running the a2ensite and disable by running the a2dissite commands

Nginx does not have these available. So to enable a site named example.com on Ubuntu for Nginx, just create a symbolic link from the sites-available to the sites-enabled directory.

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com

To disable the example.com site, just delete it from the sites-enabled directory.

sudo rm /etc/nginx/sites-enabled/example.com

After enabling or disabling a site, restart Nginx server.

sudo systemctl restart nginx.service To test if Nginx is installed and working, open your browser and browse to the server IP or hostname and you should see Nginx default page if it was installed properly.