Setting Up a Lightweight HTTP Proxy Server with Proxy.py on AWS EC2

Setting Up a Lightweight HTTP Proxy Server with Proxy.py on AWS EC2

Takahiro Iwasa
Takahiro Iwasa
2 min read
EC2 Proxy.py Python

Introduction

Proxy.py is a lightweight HTTP proxy server designed for quick and efficient deployment. This tutorial will guide you through setting up Proxy.py on an AWS EC2 instance, enabling you to access websites and APIs.

Prerequisites

Ensure you have the following:

  • An AWS EC2 instance up and running.
  • SSH access to the EC2 instance.
  • Python and pip installed on the instance.

Step 1: Installing Proxy.py

Install Proxy.py with the following command:

pip install proxy.py

Step 2: Launching Proxy.py

Start Proxy.py using this command:

proxy --port 8080

After launching, you should see logs similar to this in the terminal:

pid:3330 [I] plugins.load:85 - Loaded plugin proxy.http.proxy.HttpProxyPlugin
pid:3330 [I] tcp.listen:82 - Listening on 127.0.0.1:8080
pid:3330 [I] pool.setup:108 - Started 1 acceptors in threaded mode
...

To ensure Proxy.py runs even after closing the SSH session, use the following command:

nohup proxy --port 8080 > /dev/null &

Step 3: Testing the Proxy Server

Establish an SSH tunnel to your EC2 instance:

ssh -L 8080:localhost:8080 -i .ssh/YOUR_PRIVATE_KEY ec2-user@YOUR_HOST

Test the proxy by sending a request to Google:

curl www.google.com -x http://localhost:8080

If the proxy is working correctly, you should receive an HTML response from Google.

Conclusion

Proxy.py is a versatile and efficient tool for lightweight proxying needs, especially in scenarios where setting up a more complex solution like Nginx is unnecessary. With its minimal setup and straightforward configuration, it’s an excellent choice for developers and system administrators.

For more information, visit the official Proxy.py documentation.

Happy Coding! 🚀

Takahiro Iwasa

Takahiro Iwasa

Software Developer at KAKEHASHI Inc.
Involved in the requirements definition, design, and development of cloud-native applications using AWS. Now, building a new prescription data collection platform at KAKEHASHI Inc. Japan AWS Top Engineers 2020-2023.