How can I install and configure Nginx on the Instance?

73    Asked by CelinaLagunas in AWS , Asked on Feb 13, 2024

I am a DevOps engineer and I am responsible for provisioning and configuring servers in an AWS environment. In this particular task, I need to install Nginx on an Amazon Linux 2 EC2 Instance for hosting a new web-based application. How can I install and even configure Nginx on the Instance? 

Answered by Daniel Cameron

 In the context of AWS, you can install Nginx On Amazon Linux 2 by using the following steps:-

Connecting to the EC2 Instance

You can start by connecting to the Amazon Linux 2 EC2 Instance by using SSH:

  Ssh -I /path/to/your-key.pem ec2-user@your-ec2-public-ip

Update package repository:-

Before the process of installing Nginx, you should update the package repository so that you can ensure you have the latest package information.

Install Nginx:-

You can use the YUM package manager for the process of installation of Nginx:-

  “sudo yum install Nginx -y”

Start Nginx service

Once you have downloaded the Nginx In your particular system, you can start the service of Nginx:

  “sudo systemct1 start Nginx”

Enable Nginx to start on boot

You can ensure that the Nginx starts automatically upon booting the system.

  “sudo systemct1 enable Nginx”

Checking the status of Nginx

You should verify that the Nginx is running without any errors:-

  “sudo systemct1 status Nginx”

Adjust the setting of the firewall

If you find that the instance’s firewall is enabled then you can make sure that the HTTP traffic should be allowed to reach the server of Nginx:

  Sudo firewall-cmd –zone=public –permanent –add-service=httpSudo firewall-cmd –reload

Access the Nginx default page

You can open a browser and then navigate to the public IP address of your EC2 Instance. You should see the default Nginx welcome page which would Indicate that the Nginx has been successfully installed and it is serving the content related to the web.



Your Answer

Interviews

Parent Categories