This project provides a Docker container that combines multiple Tor instances with HAProxy for load balancing and Privoxy for HTTP proxy functionality. The setup is based on Alpine Linux.
A Docker image for this project is automatically built and pushed to GitHub Container Registry (ghcr.io) via GitHub Actions. You can pull the latest image using:
docker pull ghcr.io/perennialtech/multi-tor-proxy:latestTo build the image locally:
docker build -t multi-tor-proxy .The container orchestrates the following components:
- Multiple Tor instances
- HAProxy for load balancing across Tor instances
- Privoxy as an HTTP proxy frontend
graph LR
Client[Client]
Privoxy[Privoxy :8118]
HAProxy[HAProxy :8050]
Tor1[Tor Instance 1]
Tor2[Tor Instance 2]
TorN[Tor Instance N]
Internet[Internet]
Client <-->|HTTP| Privoxy
Client <-->|SOCKS5| HAProxy
Privoxy <-->|SOCKS5| HAProxy
HAProxy <-->|SOCKS5| Tor1
HAProxy <-->|SOCKS5| Tor2
HAProxy <-->|SOCKS5| TorN
Tor1 <--> Internet
Tor2 <--> Internet
TorN <--> Internet
The application uses the following ports:
| Service | Port Type | Port Number/Range |
|---|---|---|
| Privoxy | HTTP proxy | Set by PRIVOXY_LISTEN_ADDRESS (default: 8118) |
| HAProxy | Frontend SOCKS5 proxy | 8050 |
| Tor Instances | SOCKS | 9050 to 905(N-1), where N is the number of instances |
| Tor Instances | Control | 9053 to 905(N+2), where N is the number of instances |
| Tor Instances | DNS | 5350 to 535(N-1), where N is the number of instances |
Note
The exact number of ports used for Tor instances depends on the NUM_TOR_INSTANCES environment variable.
- Alpine Linux: 3.20.3
- Tor: 0.4.8.12-r0
- HAProxy: 2.8.10-r0
- Privoxy: 3.0.34-r2
- gosu: 1.17-r5 (from Alpine edge/testing repository)
- Multiple Tor instances for improved performance and anonymity
- HAProxy load balancing among Tor instances
- Privoxy for HTTP proxy functionality and advanced filtering
- Persistent Tor data storage using Docker volumes
- Configurable via environment variables
- Non-root execution of Tor and Privoxy processes using gosu
-
Clone this repository:
git clone https://github.com/perennialtech/multi-tor-proxy.git cd multi-tor-proxy -
Create a
.envfile based on the provided.env.example:cp .env.example .env
Adjust the variables in
.envaccording to your requirements. -
Start the container using Docker Compose:
docker compose up -d
This command will build the image if it doesn't exist and start the container in detached mode.
-
Use the Privoxy HTTP proxy:
curl --proxy http://127.0.0.1:8118 https://am.i.mullvad.net/json
-
Use the HAProxy SOCKS5 proxy:
curl --proxy socks5://127.0.0.1:8050 https://am.i.mullvad.net/json
The container is configured using environment variables. These can be set in the .env file or passed directly to the container. Key configuration options include:
NUM_TOR_INSTANCES: Number of Tor instances to run (default: 3)PRIVOXY_LISTEN_ADDRESS: Address and port for Privoxy (default: "0.0.0.0:8118")TOR_RELAY: Enable/disable relay mode (default: 0)TOR_NICKNAME: Nickname for the Tor relay (default: "torPrivoxy")TOR_BANDWIDTH_RATE: Bandwidth rate limit for the Tor relay (default: "1000000")TOR_BANDWIDTH_BURST: Bandwidth burst limit for the Tor relay (default: "2000000")TOR_EXIT_POLICY: Exit policy for the Tor relay (default: "reject :")
Refer to the .env.example file for a complete list of configuration options.
The project includes a compose.yaml file for easy deployment using Docker Compose. Key features of the Compose configuration:
- Container name and hostname:
multi-tor-proxy - Builds the image from the local Dockerfile
- Maps ports
8118(Privoxy) and8050(HAProxy) to the host - Uses the
.envfile for environment variables - Configures automatic restart (
unless-stopped) - Creates and uses a named volume
multi-tor-proxy_tor-datafor persistent Tor data
To stop the container:
docker compose downTo stop the container and remove the volume:
docker compose down -vTor data for all instances is stored in a Docker volume named multi-tor-proxy_tor-data, persisting Tor's state across container restarts.
This project is licensed under the MIT License. See the LICENSE file for details.