Setting up a Proxy Server on AWS EC2
- Launch an instance with the latest Ubuntu Server 20 AMI. See the detailed demo below on how to launch an instance in the below video:
- Now SSH to newly created Ubuntu EC2 Instance.
WINDOWS:
- Use PuTTY for SSH
LINUX:
- .Open terminal & then the directory where you downloaded the .pem file while launching the EC2 Instance.
-
- chmod - To change access permissions, change mode. To read more about chmod & its numeric mode, please refer to the following article - CHMOD
- my-key-pair.pem is the name of the .pem file which you downloaded while launching the EC2 Instance.
- Then, use the ssh command
ssh -i "my-key-pair.pem" ubuntu@ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com
where
-
- my-key-pair.pem is the name of the .pem file which you downloaded while launching the EC2 Instance.
- ubuntu is the user name.
- ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com is the DNS of your EC2 instance.
- Install the update for Ubuntu with the below commands.
sudo apt update
sudo apt upgrade
where
-
- sudo apt update- List all updates available with the permission of the root user(as we are using sudo). (Remember: It just listing the updates, not actually updating it.)
- sudo apt upgrade- This command actually installs the updates.
- We will use TinyProxy to set up our Ubuntu Server as the Proxy. By default, TinyProxy operates on Port 8888.
sudo apt install tinyproxy
- Now modify the conf file of TinyProxy to allow only the IP address of your machine/s.
Find Allow section of the conf file and add your device’s IP address so that it can be allowed to bypass the traffic.
Instructions —- Find the file directory.
- Use the command- sudo vim /etc/tinyproxy/tinyproxy.conf or sudo nano /etc/tinyproxy/tinyproxy.conf
- Press “i” on the keyboard to be able to edit the entry.
- Then press the “ESC” escape key to stop modification.
- Use “:w” to write the change and “:q” to quit
(NOTE: You can modify the port according to your need, but the default is 8888)
- We need to restart the TinyProxy service so that the changes are reflected.
sudo /etc/init.d/tinyproxy restart
- The last step would be modifying the inbound rules of the security group of our EC2 Instance such that only the trusted machines are able to access the proxy server which we created.
- Now just configure this proxy where ever you want with the Public IP address of the Instance along with port 8888 or whatever port you defined in the "tinyproxy.conf" file.
Additionally, you can associate this Instance with an Elastic IP address. So, that Public IP doesn't change even if our EC2 instance got to stop/start again & again. As public IP changes, when we stop/start the EC2 instances.