This project deploys Nginx, an open-source software for web serving, reverse proxying, caching, load balancing, media streaming, and more, on an AWS EC2 instance. It uses Terraform, a popular Infrastructure as Code (IaC) tool, to create and manage AWS resources. It also uses Ansible, a powerful automation tool for configuration management and application deployment, to install and start the Nginx service on the newly created EC2 instance.
Before you can run the scripts, you'll need:
-
An AWS account and your AWS credentials configured locally. You can set them up using the AWS CLI with the aws configure command. You will need to input your AWS Access Key ID, AWS Secret Access Key, Default region name, and Default output format.
-
Terraform installed on your machine. You can follow the installation guide on the official Terraform website.
-
Ansible installed on your machine. Installation guide can be found on the official Ansible website.
-
SSH key pair to access the EC2 instance. You should have the private key (.pem file) available on your local machine.
-
An available VPC and Subnet on AWS to host the EC2 instance.
-
Clone this repository to your local machine.
-
Update the Terraform variables in main.tf as per your setup:
- vpc_id and subnet_id for the EC2 instance.
- ssh_user usually "ubuntu" or "ec2-user" depending on the AMI.
- key_name name of the key pair in AWS.
- private_key_path the path of your private key (.pem file).
-
Initialize Terraform using the following command in the terminal:
terraform init
- Run the following command to check the changes that will be done by Terraform:
terraform plan
- Apply the changes:
terraform apply
When prompted, type yes and hit enter to proceed with the creation of the resources.
- The script should end with the public IP address of the newly created EC2 instance where Nginx is installed and running. You can access it in your web browser using the http protocol (for example, http://[ec2-instance-ip]).
Please note that the security settings as per this configuration allow all inbound connections over SSH (port 22) and HTTP (port 80). Ensure to adjust these settings as per your requirement.