prerequisites
Feature | Inbound Rules | Outbound Rules |
---|---|---|
Direction | Controls incoming traffic to the instance | Controls outgoing traffic from the instance |
Purpose | Define who can access your server | Define where your server can access |
Example | Allow HTTP (port 80) so browsers can load your site | Allow access to external APIs or databases |
Common Ports |
22 (SSH), 80 (HTTP), 443 (HTTPS) |
80 , 443 , custom DB/API ports |
Default Behavior | All inbound traffic denied unless explicitly allowed | All outbound traffic allowed unless restricted |
Use Case | Allow only specific IPs or ports to access your app | Restrict external communication for security |
Inbound Rule:
Allow TCP port 22 from 0.0.0.0/0 — for SSH access to EC2
Allow TCP port 80 from 0.0.0.0/0 — for web server access
Outbound Rule:
Allow all traffic to 0.0.0.0/0 — default for most servers
(Optional) Deny all except specific IPs/ports — for lockdown servers
Step 1: Click on "Launch Instance"
Step 2: Select "Desire OS"
Step 3: Select Instance Types & Key Value pair
Instance Type - Based on required size
Key value pair - SSH login
Step 4: Network Settings - Enable public access and private access
Step 5: Configure required storage
Step 6: Click on "Launch Instance"
Note the instance's public IP and private IP
Step 7: Once the instance is launched successfully. SSH to connect to the instance
chmod 400 "jun17.pem"
ssh -i "jun17.pem"
ubuntu@ec2-3-110-45-121.ap-south-1.compute.amazonaws.com
Install a web server to host the application
sudo apt install nginx -y
sudo nano /etc/nginx/sites-available/default
Host a static HTML pages
server {
listen 80;
server_name aws_ip;
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Restart service
sudo nginx -t
sudo systemctl restart nginx
Host React app
Install Nodejs in instance
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs
server {
listen 80;
server_name aws_ip;
location / {
proxy_pass http://localhost:3000; # or 5173, etc.
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
sudo nginx -t
sudo systemctl restart nginx
Configure firewall in nginx (OPTIONAL)
sudo ufw status
sudo ufw allow 80
sudo ufw allow 22
sudo ufw enable
Note: Use PM2 for running multiple process at the same time in single instance.
Top comments (1)
Some comments may only be visible to logged-in visitors. Sign in to view all comments.