auto assign public ip for ec2 webserver - amazon-web-services

I am going to deploy Nginx webserver to run my angular application in AWS ec2 and i have 2 subnets public and private. to reach my nginx web application I will use ALB which is in public subnet, now my question is
can i deploy the Nginx webserver(ec2) in private subnet.
in which case I should enable public IP to my nginx ec2 server

You should not assign a public IP address to the nginx EC2 server because:
It should only be accessed via the Load Balancer, and
It is in a private subnet, so the Public IP address will not work (that is, traffic will not be routed to the instance)
You should deploy the Load Balancer in the public subnet and the EC2 instance in the private subnet.

can i deploy the Nginx webserver(ec2) in private subnet.
Yes, you can. In ideal case the private webserver does not need any internet access.
in which case I should enable public IP to my nginx ec2 server
The server does not require public IP. If you place it in a private subnet, and you want your server to access internet (e.g. to install packages or updates) you have to setup NAT gateway in a public subnet.

Related

SSH using Public IP over the VPN

I have an EC2 instance launched in Private Subnet.
I have also launched an AWS Client VPN and did all of the configurations and I am able to connect to my EC2 instance via Private IP.
There is a service running on Port 25, I am able to telnet to that as well using the Private IP.
But when I try to do telnet using the Public IP of the Instance, I am not able to do so. Also, I am not able to ssh into Instance when I am connected to VPN using the Public IP.
How can I ssh into my EC2 Instance using Public IP when I am connected to VPN?
I don't want to add my machine's Public IP in the Security Group and then do the SSH.
If an Amazon EC2 instance is in a private subnet (defined as having a Route Table that does not point to an Internet Gateway), then the instance will not be reachable via public IP address.
Public IP addresses are routed via the Internet Gateway. Since there is no route between the Internet Gateway and the instance, it cannot be reached via the public IP address.

AWS EC2 IPv4 Public Address not reachable

I have deployed a Strapi.io app on AWS EC2 Following the documentation provided by strapi.io on their site.
Everything went great but when i try to reach the public IP of my EC2 instance, it is unreachable.
I have checked assigned an elastic ip.
I have also checked the gateway and security group, every thing is good but still my IP is unreachable.
Security Group Setting
Check your routing table of the subnet. If it routes the cidr 0.0.0.0/0 to the internet gateway, then the subnet is public and can connect by the public ip. If it routes to the NAT gateway, then the subnet is private and you need the load balancer or bastion to connect the ec2 on the private subnet by private ip. On the private subnet, the public ip is useless.
The issue here is that you need a web serever or reverse proxy like nginx, apache to listen on the port 80 and server your application. Currently, you would not have a web server configured for your app so you do not get any response when you hit the IP Address in your browser.

where to place web app server in AWS VPC ?

What is the best practice to place web app server in AWS VPC? In Private subnet with ELB or Public subnet?
As per my understanding the best practice is to place web app server in public subnet.
Do not place the web server in the public subnet. Launch them in a private subnet and front end them with ELB that runs in a public subnet. You do not want to deal with DDoS attacks on your web server, leave that to ELB which does an excellent job in addition to load balancing.
See:
How do I connect a public-facing load balancer to EC2 instances that have private IP addresses?
Scenario 2: VPC with Public and Private Subnets (NAT)

Using a NAT for Public Facing AWS Web Server

I have read articles describing placing a public facing web server in a public subnet and placing application servers in a private subnet. Furthermore, using a NAT Gateway to allow servers in a private subnet to communicate with the Internet, etc.
Alternatively, is it acceptable to also place your web server in the private subnet and flow all Internet traffic through the NAT Gateway?
If the webserver's in the private subnet, it won't be reachable from the Internet. NAT gateways give instances outgoing access, not incoming.
However, you can have webservers in a private subnet, and serve them via an Elastic Load Balancer placed in a public subnet.

AWS EC2 public vs private IPs

Is there any difference in using private and public IPs for communicating with other AWS instances? Do private IPs provide any more functionality(or security) as compared to using public IPs?
A few differences:
Instances launched in a VPC, the private IP address remains associated with the network interface when the instance is stopped and restarted. The public IP would get released when you stop and restart unless you use Elastic IP.
If you have a pure backend-service, you could give it only a private IP and create a VPN connection into your VPC. That way, an attacker would not be able to even contact your backend-service unless he gained access to your VPN.
Using the private IP doesn't result in bandwidth charges.
So deploy your EC2 instance in the VPC, so that it gets a static internal IP. If you like, set up an Elastic IP. If you resolve the Elastic IP from the internal network, you will get the private IP and the public IP when resolved from externally. https://alestic.com/2009/06/ec2-elastic-ip-internal/