Nginx
Class 38th AWS Nginx June 3rd
Any application to host minimum three serves are mandatory
Webserver -->Application -->db server
If you open any host url for ex: Swiggy --> it will go to webserver (Front end code, html,css,java script)
User -->Server(Webserver)-->App server --> Db server [AKA also know as]
Webserver:(Appache,Nginx,IIS,websphere)
AKA :The presentation layer
Purpose :to show the app
Who :UI/UX(front-end dev)
What :Web technologies
Ex:html,css,js
NGINX IS AN WEBSERVER
- USED TO SERVE STATIC FILES (FRONT END CODE)
- 35% of website all over the world
- It got officially release in Oct 2004
- It was created to solve the problem of c10k (connect 10k Sessions)
- Free & open source
- Easy to install and use
- port 80
Nginx will overcome the problem 10k session handle ,all webserver port 80
Advantages :
- It uses less memory and resources (10 MB software).
- Nginx makes the website faster (give you better ranking in website)
- helps to get a better google ranking
- handling thousands of connections same time.
- Load balancing
- Acts a proxy & reverse server
Website Ranking checking in Google using
https://sitechecker.pro/rank-checker/ for specific website to check
https://www.similarweb.com/top-websites/ top 10 website to check
As you see below Per day Google access 10.22 minutes Avg ,Youtube 20.03 minute per day.
Forward Proxy (just like tool free number,fake ip address)
Advantages:- Hide A client's IP address
- Protect data and resources from malicious actors
- Restrict access to specific users/groups
- Speed results from cache
- Hide A server IP address
- Protect against DDOS attacks (Distributed Denial of service) millions of request give to faker make the server down
- Speed Access to Specific Users/Group based on location
- Speed results from cache
root@ip-172-31-42-237:~/amazonapp# cat amazon.sh
apt update
apt install apache2
cd /var/www/html : all frontend code
git clone https://github.com/Ironhack-Archive/online-clone-amazon.git
mv online-clone-amazon/* .
root@ip-172-31-42-237:~/amazonapp# sh amazon.sh
Step3: using your public Ip of the your instance ,amazon web application opened successfully.
This site can’t be reached
Step5: if you want to block the website
root@ip-172-31-42-237:/var/www/html# vim /etc/nginx/nginx.conf
http {
deny all;
root@ip-172-31-42-237:/var/www/html# systemctl restart nginx.service
Website unable to access getting below error
403 Forbidden
84.225.123.245 - - [09/Jun/2025:11:16:27 +0000] "GET / HTTP/1.1" 403 195 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"
Step6: Deny for Single user access
root@ip-172-31-42-237:/var/www/html# vim /etc/nginx/nginx.conf
http {
deny 84.225.123.245/32;
root@ip-172-31-42-237:/var/www/html# systemctl restart nginx.service
Getting error for my ip address
403 Forbidden
See here using ip address http://54.198.138.13/ instead of that will give to Unique domain name
http://54.198.138.13/ --> Amazon.com (domain)
--Thanks
Just Knowledge Purpose
Instead of Chat gpt, use Visual studio code setup the copilot,text the requirement ,the code will generated automatically
This is the way AI (your are experienced give terraform code for ec2 and make sure the having full secure)
this the way you need search, see below ,it will give complete text for IAM, security group everything.
// main.tf
provider "aws" {
region = "us-east-1"
}
data "aws_ami" "amazon_linux" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm-*-x86_64-gp2"]
}
}
resource "aws_security_group" "ec2_sg" {
name = "secure-ec2-sg"
description = "Allow SSH only from my IP"
vpc_id = "<YOUR_VPC_ID>"
ingress {
description = "SSH from my IP"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["<YOUR_IP>/32"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_iam_role" "ec2_role" {
name = "ec2-least-privilege-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "ec2.amazonaws.com"
}
}]
})
}
resource "aws_iam_instance_profile" "ec2_profile" {
name = "ec2-instance-profile"
role = aws_iam_role.ec2_role.name
}
resource "aws_instance" "secure_ec2" {
ami = data.aws_ami.amazon_linux.id
instance_type = "t3.micro"
subnet_id = "<YOUR_PRIVATE_SUBNET_ID>"
vpc_security_group_ids = [aws_security_group.ec2_sg.id]
associate_public_ip_address = false
iam_instance_profile = aws_iam_instance_profile.ec2_profile.name
root_block_device {
encrypted = true
volume_size = 8
volume_type = "gp3"
}
tags = {
Name = "secure-ec2"
}
}
Just Knowledge Purpose
If you want linux server use this website for 1 hr , click ubuntu free
https://killercoda.com/playgrounds
--Thanks
No comments:
Post a Comment