AWS

Set-up a Nginx web server on ubuntu 18.04 EC2 Instance AWS

When it comes to a high-end performance web server with maximum throughput, Nginx is the only answer. In today’s post, we are going to learn about the same, and how to set-up a nginx web server.

Note: Before going further, make sure you know -> “How to set-up an EC2 instance“.

Now that you know the basic instance creation on AWS EC2, follow the forthcoming steps in order to set-up nginx web server.

Step 1: We have to login into our EC2 instance, as shown below:

Make sure you replace “testing.pem” with your named private key and IP Address with your instance’s IP Address.

 login into aws ec2 ubuntu 18.04 instance
Login into AWS EC2 Ubuntu 18.04 instance

Step 2: Now, install the main component, which is “nginx” in this case. Do as shown below:

install nginx web server on aws ec2 ubuntu 18.04 instance
Install Nginx web server on AWS EC2 Ubuntu 18.04 instance

Step 3: Look for the configuration files and directories for the nginx web server on AWS EC2 Ubuntu 18.04 instance.

Following are the files and directories we must pay attention to, “sites-available” have a “default” file which is used “by default” if no other setting is added or altered.

all nginx configuration files and directories on aws ec2 ubuntu 18.04
All Nginx configuration files and directories on AWS EC2 Ubuntu 18.04

Step 4: Now, check whether the “nginx” web server is running or not.

Check whether Nginx is running or not on EC2 Ubuntu 18.04
Check whether Nginx is running or not on EC2 Ubuntu 18.04

Step 5: Go to EC2 dashboard and look for IPv4 address as shown below, simply copy that IP Address, for now.

Check IP address of an instance in aws ec2 dashboard
Check IP Address of an instance in AWS EC2 dashboard

Step 6: Now, we have to access and confirm that our web sever is working.

As shown in the “gif” below, after pasting the IP Address copied in the previous, we are able to access our default “html” page of our nginx web server.

Enter instance IP address in the url bar of browser
Enter instance IP Address in the URL bar of browser

Question: What if we want to show some “Custom HTML” to our web server’s visitors?

Answer: In order to achieve that, we have to navigate to “/var/www/html“, then after that create a file named as “index.html” and add anything you want to add, we have added “Hello from custom html file.” as shown in the next step.

Step 7: Creating a custom html file for our nginx web server running in EC2 ubuntu 18.04 instance.

Adding a custom html file in nginx server on ec2 ubuntu 18.04
Adding a custom HTML file in Nginx server on EC2 Ubuntu 18.04

Step 8: Now, access our previously added “custom html” file, as shown below we are successfull in doing so.

Accessing custom html file in nginx on ec2 ubuntu 18.04
Accessing custom HTML file in Nginx on EC2 Ubuntu 18.04

Comment here