The Best Web Server In The Market is Nginx. And How To Configure Nginx For Your Web App With Linux Hosting

Technology Reads Mar 23, 2020

Excerpt

The Nginx open-source web server is modern and user-friendly. And it has become default reverse-proxy for the modern web applications.

Introduction

In the not too distant past, in the age when PHP and Ruby Rails were the default programming language,  the default web server powered internet applications were Apache, which is cumbersome to set up and maintain for daily operations.

The arrival of Nginx, open-source webserver, has virtually changed that landscape with its easy to configure and user-friendly application. As per the Nginx web site, currently, this new webserver powers 400 million websites, both big heavy-traffic to single-page personal profile websites today.

The Best Web Server In The Market is Nginx. And How To Configure Nginx For Your Web App With Linux Hosting - renttheant.com

Why you need an Nginx web server?

Nginx is easier to learn and configure. Highly flexible than other options available like Apache.


You can use them as both web server or reverse proxy to actual web server hosting your web applications.

One such webserver heavily used is Linux based server OS, and has multiple open-source distributions are available in the market for hosting web applications. And most of these Linux OS have already prebuilt Nginx packages available.

Which means we can do without the grunt work of installing Nginx from source files. And skip entirely the hard work of compiling and installing additional dependency necessary to complete the installation. So, in the case of Linux OS, it just the matter of choosing the right prebuilt package and complete the installation with few simple cli commands.

How to install Nginx on Ubuntu?

Ubuntu package manager has pre-built Nginx available. We can directly install using below commands.

$ sudo apt update

$ sudo apt install nginx

Allowing Nginx in the firewall

Prebuilt package installation has already taken care of by registering as services with the UFW firewall. You have to access the app list and confirm that the Nginx app available in the app list.

How to validate the UFW firewall

First list the available app

$ sudo ufw app list

Then the command line interface should print information like below.

Status: active

To                 Action      From

OpenSSH            ALLOW       Anywhere
OpenSSH (v6)       ALLOW       Anywhere (v6)

Make sure that Nginx related entries available for Nginx HTTP Full, Nginx HTTP, Nginx HTTPS.


Now, if by design or your current app is not configured to handle HTTPS, then enable only Nginx HTTP.

$ sudo ufw allow 'Nginx HTTP'

Otherwise, to enable both HTTP and HTTPS, use this Nginx Full profile to configure both access to 80, and 443 encrypted traffics.

You can enable Nginx in the firewall using this command.

$ sudo ufw allow 'Nginx Full'

Then validate the status.

$ sudo ufw status

Cli will list the current status of the application registered.

Status: active

To                 Action      From

OpenSSH            ALLOW       Anywhere
OpenSSH (v6)       ALLOW       Anywhere (v6)
Nginx HTTP         ALLOW       Anywhere
Nginx HTTPS (v6)   ALLOW       Anywhere (v6)

Validating Nginx

At the end of this installation, you can start the Nginx Web server.

$ sudo nginx

Then, validate the server status using systemctl command.

$ sudo systemctl status nginx

You will get output like this below.

Status: active

To                 Action      From

OpenSSH            ALLOW       Anywhere
OpenSSH (v6)       ALLOW       Anywhere (v6)
Nginx HTTP         ALLOW       Anywhere
Nginx HTTPS (v6)   ALLOW       Anywhere (v6)

Now, it's the time to test whether Nginx is serving the default page.

I am assuming that you have installed your server somewhere in cloud computing service providers like Digital Ocean.

Then type the server IP address in the browser and see what's coming.

Some of the frequent Nginx Cli commands used and usage in the day-to-day operation.

Start the Nginx

$ sudo systemctl start nginx

Restart the Nginx

$ sudo systemctl restart nginx

Stop the Nginx

$ sudo systemctl stop nginx

Reload the Nginx
This command is something you will be using whenever making changes to Nginx configuration or Updating domains configured to process your website.

$ sudo systemctl reload nginx

To enable the Nginx auto start when the server boots up.

$ sudo systemctl enable nginx

To stop such auto start, then use this command.

$ sudo systemctl disable nginx

What is next and possible with Nginx?

Configure Nginx for multiple domains and subdomains.

How To Configure Nginx Server Block For Multiple Domains Hosting
If you are setting up multiple domains within a single Linux server in the cloud; then, it’s easy to do with the Nginx Server Block directive. Here is how.
How To Configure Nginx Server Block For Multiple Domains Hosting - renttheant.com

Securing traffic with Let's Encrypt Open SSL

How To Secure Your Web Application With Let’s Encrypt Open SSL
In the last few years, Let’s Encrypt open-source certificate has become the goto option to encrypt your website communication with your server on the internet.
How To Secure Your Web Application With Let's Encrypt Open SSL - renttheant.com

Web application redirect and dynamic navigation

Inner Voice

I am "Rent The Ant" Inner Voice. The collective voice of our team both in-house and partners.