How Can I Install Nginx on AWS EC2 Ubuntu 16.04 Machine and host Multiple Websites.
📚 tutorials

How Can I Install Nginx on AWS EC2 Ubuntu 16.04 Machine and host Multiple Websites.

2 min read 307 words
2 min read
ShareWhatsAppPost on X
  • 1Nginx is a versatile web server that can function as a reverse proxy, load balancer, and HTTP cache.
  • 2Installation on Ubuntu 16.04 is simple, requiring an update and installation via the command line.
  • 3To host multiple websites, create configuration files in '/etc/nginx/sites-available/' and link them to '/etc/nginx/sites-enabled/'.

AI-generated summary · May not capture all nuances

Key Insight
AskGif

"Nginx is a versatile web server that can function as a reverse proxy, load balancer, and HTTP cache."

How Can I Install Nginx on AWS EC2 Ubuntu 16.04 Machine and host Multiple Websites.

Nginx ( /ˌɛndʒɪnˈɛks/ EN-jin-EKS[8]) (stylized as NGINX, NGiИX or nginx) is a web server which can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. The software was created by Igor Sysoev and first publicly released in 2004. A company of the same name was founded in 2011 to provide support and Nginx plus paid software.

Nginx is free and open-source software, released under the terms of a BSD-like license. A large fraction of web servers use NGINX, often as a load balancer.

Install Nginx

Installation of Nginx is straightforward as it is available in Ubuntu's default repository.

First, we will update our local package index, then we will install Nginx:

$ sudo apt-get update

$ sudo apt-get install nginx

Now we need to adjust the firewall.

First, we will reconfigure our firewall to allow access to the service. Nginx registers itself as a service with ufw, which makes it easy to allow Nginx access.

$ sudo ufw app list

Output:

Available applications: Nginx Full Nginx HTTP Nginx HTTPS OpenSSH

Check your web server:

$ systemctl status nginx

Host Multiple Websites on Nginx:

After a successful install, go to the following path: /etc/nginx/sites-enabled. Remove the default file as we will not be using it.

rm -rf default (Normally -rf is used to delete folder and its sub contents)

Now go to the following path: /etc/nginx/sites-available/. Create a file for your website (preferably your website name).

vi yourwebsite

Write the following code in the file, specifying the port and host you want to point to:

server {

    listen 80;

    server_name subdomain.yourwebsite.com;

    location / {

        proxy_pass "http://127.0.0.1:8080";

    }

}

Save the file. Now you have to link the file from sites-available to the file in sites-enabled. Use the following code:

ln -s /etc/nginx/sites-available/yourwebsite /etc/nginx/sites-enabled/yourwebsite

Now check the correctness of the file and restart Nginx to see the changes:

nginx -t

service nginx restart

Install Nginx
Install Nginx

Enjoyed this article?

Share it with someone who'd find it useful.

ShareWhatsAppPost on X

AskGif

Published on 2 July 2018 · 2 min read · 307 words

Part of AskGif Blog · tutorials

You might also like

How Can I Install Nginx on AWS EC2 Ubuntu 16.04 Machine and host Multiple Websites. | AskGif Blog