Skip to content

Instantly share code, notes, and snippets.

@webinista
Last active August 18, 2024 18:20
Show Gist options
  • Save webinista/812c20247a6c21e639ce to your computer and use it in GitHub Desktop.
Save webinista/812c20247a6c21e639ce to your computer and use it in GitHub Desktop.
Create a proxy server on an Amazon EC2 (VPC) instance

This will create a proxy server in whatever your availability zone your VPC is in. For me, that's us-east-1b. For you, that may be something different. Steps 10+ should more or less work regardless of your provider since those steps cover the setup and configuration of TinyProxy.

  1. Click the Launch Instance button.

  2. Choose Ubuntu Server 14.04 LTS (HVM), SSD Volume Type. This isn't strictly necessary. If you choose another OS, check its documentation for how to install new packages.

  3. On the Choose an Instance Type screen, select t2.micro. It's Free Tier eligible.

  4. Click the Next: ... buttons until you reach the Configure Security Group screen.

    • You may wish to reduce the amount of storage on the Add Storage screen. This is optional.
    • You may wish to add a tag on the Tag Instance screen. This is also optional.
  5. On the Configure Security Group screen:

    • Select Create a new security group.
    • On the first line, verify that Type is SSH, Protocol is TCP and the Port Range is 22. Under Source, select "My IP" from the drop down menu. This restrict incoming connections to those from your IP address.
    • Click the Add Rule button.
    • Select Custom TCP Rule. Make sure the Protocol is TCP, and the Port Range is 8888. Under Source, select My IP from the drop down menu. This opens Port 8888.
  6. Click Review and Launch, and on the following screen, click Launch.

  7. Make sure Use an existing key pair is selected, or create a new key. If you are using an existing pair, check the acknolwedgement box.

  8. Go to View Instances.

  9. Select the instance you just created. Click the Connect button above the list of instances.

  10. Using a terminal window, run the SSH command listed, e.g. ssh -i /path/to/yourkey.pem ubuntu@xxx.xxx.xxxx, where xxx.xxx.xxxx is the IP of your EC2 or VPC instance. The first time, SSH will tell you The authenticity of host 'xxx.xxx.xxxx (xxx.xxx.xxxx)' can't be established. Continue anyway.

  11. Run this command: sudo apt-get install tinyproxy (or the package installation command for the flavor of Linux your instance is using).

  12. Edit /etc/tinyproxy.conf using the editor of your choice. You'll probably need to use sudo.

  13. Make sure that /etc/tinyproxy.conf file contains the lines Port 8888 and Allow xxx.xxx.xxx.xxxx where xxx.xxx.xxx.xxxx is your IP address. (Check your IP address by running curl ipecho.net/plain from another Terminal window, or use WhatIsMyIP.com).

  14. Start TinyProxy using /etc/init.d/tinyproxy start. You may want to set this up in a cron job to save memory as Justin McCandless suggests. I usually shut down the instance after I'm done with it, so I haven't bothered doing this.

  15. Most other tutorials about this subject say to run the command below with the -N flag. The -N flag means Do not execute a remote command. Using it didn't work for me. So I ran the command below without that flag. Here, 3128 is the port that we'll use to connect to localhost. And it will be forwarded to port 8888 of our EC2 VPC instance.

    ssh -L 3128:localhost:8888 -i /path/to/yourkey.pem ubuntu@xxx.xxx.xxxx 
    
  16. Change your browser or operating system's proxy settings.

    • Make the host localhost
    • Set the proxy port to 3128
    • Verify that this went well by running curl ipecho.net/plain from another Terminal window, or by using WhatIsMyIP.com. Your IP should match that of your VPC.
@tegila
Copy link

tegila commented Sep 14, 2018

Point 15 - I had to run this as
ssh -NL 3128:localhost:2908 -i my.pem ec2-user@myserver.com

the -N was required. (I am on mac)

I do the same on amazon ec2 but it's dropping my connection after a few hours.
client:
ssh -N -R2020:localhost:22 ec2-user@.....compute.amazonaws.com (still running)

server:
nmap localhost -p 2020
PORT STATE SERVICE 2020/tcp closed unknown

Hang out after some time, normally when i want use it (haha)
any ideas for new try? I already tried autossh unsuccessfully =\

@SheldonWangRJT
Copy link

Can I open more than one instances and then map more each localhost port to a single instance to get more than one proxies working from my machine?

@GeekStocks
Copy link

+1 for the comment by @connorbode

might have to run apt-get update before step 11

@zdenekslavik
Copy link

Or use free tool such https://createproxy.com to create Amazon AWS proxy servers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment