In this post I show you how to setup a web proxy with Docker in no time. But first of all we should ask ourselves why do we actually want to do that?
Example code: https://github.com/stefpe/squid_proxy
Why a proxy?
A proxy is sitting between a client(sending a request ) and a server(responding to the client). The proxy acts as client in front of the server
- Caching server responses
- Enforce network access policies by filtering the client requests
- Reverse proxy
- Monitoring user traffic
- Page fragment caching via ESI (e.g. Symfony framework)
- Deploy a traffic proxy in another country/region to unblock foreign checks
As you can see a proxy offers a lot of possibilities to improve the performance and exprience of your application setup and makes your daily dev life easier.
Let’s run a proxy — Squid (old but gold)
We take it easy and use a squid proxy image ready to lift off. Squid is also easy to install on ubuntu with a simple apt install squid. So here’s the docker-compose.yml to setup the proxy:
In the github project linked to this post you can find a custom squid.conf file that I already adjusted to work as simple bypass proxy server.
Tweaking the config
As you can see above in the docker-compose.yml, we can adjust the config by overwriting it via a volume mount. What got changed to be a bypass proxy?
- Disable caching and avoid autogenerating the defaul log folder:
cache deny all
- Disable access log(optional):
- Allow connecting to it from everywhere (may vary for your prod setup)
http_access allow all