How to connect to a webserver on ec2 'privately'

僤鯓⒐⒋嵵緔 提交于 2019-11-30 16:23:24

You could setup your web server to listen only on 127.0.0.1 (rather than 0.0.0.0) and then use SSH to tunnel a connection from your local machine to the instance.

From your desktop, setup the SSH connection:

$ ssh -L 3000:localhost:80 ec2-user@ec2-instance.amazonaws.com

Then visit http://localhost:3000 in your browser and it will forward port 3000 on your desktop to port 80 on the instance, via the SSH connection.

You don't need an EIP to access your instance - it has a public DNS name associated with it automatically.

Create a security group that only allows traffic from your IP (the IP of the machine running the browser where you will do the testing) to the web server port (80, probably) and assign this security group to your ec2 instance.

This way only you can access the web app.

If you need to work from different locations, write a simple script to update the security group and add your current IP. These changes are applied immediately and do not require a restart. You can grab your current IP from whatismyip and use the Amazon SDK to update the security group.

If you want an EC2 instance that is truly private, you need to look at launching it inside of a VPC. You'll want a Bastion Host in your public subnet and your instance in the private subnet.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!