How to set up and use proxy in your server | Docker | Docker-compose | Proxy.py

Search for a command to run...

This is a good guide but in case you wanted to use Docker, they have started releasing official images too. Hence the steps you just mentioned can be skipped.
Django middleware is a powerful tool that allows you to process requests and responses globally across your entire Django application. In this post, we'll explore what middleware is, how it works, and walk through some practical examples. What is Dja...
Large Language Models (LLMs) have taken the world by storm, powering everything from smart search engines to intelligent business automation. But as their use grows, so does the need to monitor, evaluate, and debug these complex AI systems in real ti...

Have you ever had your code become too tightly coupled, making it hard to test and maintain? Some people certainly have. Let me share a story about how dependency injection would help you write better, more maintainable Go code. The Problem: A Coffee...
Domain-Driven Design (DDD) is an approach to software development that focuses on understanding and modeling the business domain. In this post, we'll explore how to implement DDD principles using Go, with practical examples and clear explanations. Wh...
I recently tackled an interesting challenge that I think could benefit others in the community. The problem? Creating a symmetrical ManyToMany filter widget in the Django admin dashboard. You know, the kind where you can filter and select related obj...

Django middleware is a powerful tool that allows you to process requests and responses globally across your entire Django application. In this post, we'll explore what middleware is, how it works, and walk through some practical examples. What is Dja...

I wanted to run a proxy in my server, I tried everything but still failed to set it up. I tried mitmproxy, squid, and some other proxies that I forgot, yet I somehow failed in all of them.
After researching a little more I finally found a solution that works perfectly. Proxy.py
This awesome tool is written in python, has docker configurations, and HTTPS certificate generator.
So let's start.
I reckon that you are already on your server's terminal, you have git and python3-virtualenv installed.
git clone https://github.com/abhinavsingh/proxy.py.git
cd proxy.py
python3 -m venv env
. env/bin/activate
pip install -r requirements.txt
So if you run all commands so far, you should be good.
Now, this is where we do a little customization. In proxy.py docs, they are building and running containers through docker engine, but we will create our own docker-compose file for more comfort.
if you don't have already installed docker and docker-compose please follow these links:
for docker: docker/download
for docker-compose (ubuntu): linuxize/docker-compose
Let's dig in.
create a file called docker-compose.yml in our cloned directory (proxy.py)
nano docker-compose.yml
paste this context
version: "3"
services:
proxy:
build: .
container_name: custom-proxy
ports:
- "8899:8899"
restart: always
if you have an entry for hosts file you can use extra-hosts
here is sample
services:
proxy:
build: .
container_name: custom-proxy
ports:
- "8899:8899"
restart: always
extra_hosts:
- "example.com:1.2.3.4"
Let me break these lines for you
proxy is just the name of the service
build is where our Dockerfile is located (yes it's in the current directory!)
container_name is not necessary, I just did it because I like it that way
ports: we expose the ports to the public (proxy.py default is 8899)
restart: always is simply saying start running container again if an error occurs
That's that.
Now that we have our docker-compose file we can update and run our containers more easily! Run the following command to build and get your container up.
sudo docker-compose build
when this command finishes you'll have something like this
...
Step 14/15 : ENTRYPOINT [ "proxy" ]
---> Using cache
---> a18dd7a78abb
Step 15/15 : CMD [ "--hostname=0.0.0.0" ]
---> Using cache
---> 012db77b2da2
Successfully built 012db77b2da2
Successfully tagged proxypy_proxy:latest
to get you container up and running
sudo docker-compose up
note: add -d parameter at the end to run in the background
Creating exbir-proxy ... done
Attaching to exbir-proxy
exbir-proxy | 2020-12-04 18:43:35,267 - pid:1 [I] load_plugins:334 - Loaded plugin proxy.http.proxy.HttpProxyPlugin
exbir-proxy | 2020-12-04 18:43:35,268 - pid:1 [I] listen:113 - Listening on 0.0.0.0:8899
exbir-proxy | 2020-12-04 18:43:35,277 - pid:1 [I] start_workers:136 - Started 2 workers
CONGRATULATIONS! your proxy works in your server on port 8899!
At this point, I have a little bonus for you. If you have your own customizations too, to make docker-compose controls easier, go ahead and make temporary alias for yourself.
alias dd="sudo docker-compose down -v && sudo docker-compose build && sudo docker-compose up -d"
You can add it to your .bashrc (or other shells) file if you want to make it permanent.
Please ask me any questions related to this post!