Installing Ngnix in a EC2 instance using User data.
In this project, I am going to show how to create an EC2 instance with a Nginx Web Server. We are going to install the Nginx Web Server using a Bash Script in User Data.
To do list:
1. Create a t2.micro EC2 instance with the OS of your choice (Just make sure it is free tier).
2. In the user-data field, use a script that updates all packages, installs NGINX, and start the service.
3. Verify that the instance has the NGINX webserver downloaded and installed through the public IP.
Create an EC2 Instance
In your AWS management console go to EC2 and launch instance.
In next window give your instance a name if you like. Select your key pair or create one if you don’t have one. Then move on to instance type.
As you scroll down you will see “Additional”. Click that drop down and input your script into User data.
#This is a script to install Nginx
sudo yum update -y
sudo amazon-linux-extras install nginx1 -y
sudo systemctl enable nginx
sudo systemctl start nginx
Complete your EC2 launch by clicking launch instance.
After creating your EC2 instance wait a few minutes to let it provision before connecting. Once done connect to your EC2 instance. You should see the EC2 prompt come up. Now grab the public IP address and enter it into a new web browser. The Nginx welcome page should be displayed, and you’re done!