Running Proxy.py as a Lightweight HTTP Proxy on EC2
Running Proxy.py on an EC2 instance and reaching it safely through an SSH tunnel, since the proxy has no authentication of its own.
Proxy.py is a lightweight HTTP proxy server that runs well on a small EC2 instance for testing or tunneling purposes.
On May 27, 2022, AWS introduced port forwarding to remote hosts. For more information, please refer to the official documentation.
Setting Up
Install Proxy.py:
pip install proxy.pyStart Proxy.py using this command:
proxy --port 8080To keep Proxy.py running after the SSH session closes, use the following command:
nohup proxy --port 8080 > /dev/null &After launching, you should see logs similar to this in the terminal:
pid:3330 [I] plugins.load:85 - Loaded plugin proxy.http.proxy.HttpProxyPluginpid:3330 [I] tcp.listen:82 - Listening on 127.0.0.1:8080pid:3330 [I] pool.setup:108 - Started 1 acceptors in threaded mode...Testing
Establish an SSH tunnel to your EC2 instance:
ssh -L 8080:localhost:8080 -i .ssh/YOUR_PRIVATE_KEY ec2-user@YOUR_HOSTTest the proxy by sending a request to Google:
curl www.google.com -x http://localhost:8080If the proxy is working correctly, you should receive an HTML response from Google.
Conclusion
Proxy.py and an SSH tunnel provide a lightweight HTTP proxy on an EC2 instance without exposing an unauthenticated proxy port.
proxy --port 8080 starts listening without authentication. The ssh -L 8080:localhost:8080 tunnel provides access without opening port 8080 in the instance’s security group; exposing that port could turn the server into an open proxy.
Running nohup proxy --port 8080 > /dev/null & keeps the process alive after the SSH session ends. Before leaving it unattended, confirm that it is bound to 127.0.0.1 and that the security group has no inbound rule for port 8080.
Related posts
Monitoring OPC UA Variable Nodes with Python
Subscribing to OPC UA variable node changes with opcua-asyncio so the client reacts to pushed updates instead of polling.
Performing OCR on Japanese PDFs Using Tesseract and Pytesseract
Extracting Japanese text from a PDF with Tesseract OCR v4 and pytesseract, including the normalization step needed to clean up the output.
Installing Python Packages Without Internet Access
Download Python packages on a connected machine, transfer them, and install them in an environment without internet access.
Connecting to EC2 with Session Manager (No SSH Required)
Opening a shell on an EC2 instance through Systems Manager's Session Manager, with no SSH keys, bastion host, or open port 22 required.
Debugging PHP Remotely on AWS EC2 with PhpStorm and Xdebug
Remote debugging a PHP application on EC2 with PhpStorm and Xdebug, from the server-side ini settings to the IDE's path mapping.
