Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sadasant/3f25aef6010aa0bae01a676e50e2e4bc to your computer and use it in GitHub Desktop.
Save sadasant/3f25aef6010aa0bae01a676e50e2e4bc 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment