rotating-tor-http-proxy

May 8, 2026 ยท View on GitHub

GitHub Docker Image Version (latest semver) GitHub Workflow Status Docker Pulls Docker Image Size (latest semver)

rotating-tor-http-proxy

This Docker image provides one HTTP proxy endpoint with many IP addresses for use scenarios like web crawling.

Screenshot

Behind the scene, it has a HAProxy sitting in front of multiple pairs of Privoxy-Tor. The HAProxy dispatches the incoming requests to the Privoxy instances with a round-robin strategy.

Usage

This image is multi-platform enabled, currently supporting:

  • amd64 (x86_64)
  • arm64 (aarch64)
  • arm/v7 (armhf)
  • arm/v6 (armel)

Simple case

docker run --rm -it -p 3128:3128 zhaowde/rotating-tor-http-proxy

At the host, 127.0.0.1:3128 is the HTTP/HTTPS proxy address.

Moreover

docker run --rm -it -p 3128:3128 -p 4444:4444 -e "TOR_INSTANCES=5" -e "TOR_REBUILD_INTERVAL=3600" -e "TOR_EXIT_COUNTRY=de,ch,at" zhaowde/rotating-tor-http-proxy

Port 4444/TCP

Port 4444/TCP can be mapped to the host if HAProxy stats information is needed. With docker run -p 4444:4444, the HAProxy statistics report is available at http://127.0.0.1:4444. An article from the HAProxy official blog explains in detail how to understand this report.

TOR_INSTANCES

Environment variable TOR_INSTANCES can be used to config the number of concurrent Tor clients (as well as the associated Privoxy instances). The default is 10, and the valid value is purposely limited to the range between 1 and 40.

TOR_REBUILD_INTERVAL

Each Tor client attempts to build a new circuit (results in a new outbound IP address) every 30 seconds. Every 30 minutes, this image rebuilds all the circuits. This interval can be changed with environment variable TOR_REBUILD_INTERVAL, the default value is 1800 seconds, while it can be set up any number greater than 600 seconds.

TOR_EXIT_COUNTRY

For some crawling tasks, it requires limiting the IP addresses to a certain country to avoid triggering the unnecessary recaptcha verification. Environment variable TOR_EXIT_COUNTRY can be used to specify a country (or a list of countries). Please note the following remarks:

  • Note 1: Modifying the way that Tor creates its circuits is strongly discouraged, overriding the entry/exit nodes can compromise the anonymity.

  • Note 2: The tor bridge is configured to strictly respect the exit countries if it is specified. For the countries with too fewer exit nodes (e.g., Switzerland), it would take significantly longer time to build up the circuit.

  • Note 3: The environment variable accepts a single country code (e.g., TOR_EXIT_COUNTRY=de) or a comma-separated list (e.g., TOR_EXIT_COUNTRY=de,at,ch)

  • Note 4: The acceptable country codes:

    CountryCodeCountryCodeCountryCodeCountryCodeCountryCodeCountryCode
    ASCENSION ISLANDacAFGHANISTANafALANDaxALBANIAalALGERIAdzANDORRAad
    ANGOLAaoANGUILLAaiANTARCTICAaqANTIGUA AND BARBUDAagARGENTINA REPUBLICarARMENIAam
    ARUBAawAUSTRALIAauAUSTRIAatAZERBAIJANazBAHAMASbsBAHRAINbh
    BANGLADESHbdBARBADOSbbBELARUSbyBELGIUMbeBELIZEbzBENINbj
    BERMUDAbmBHUTANbtBOLIVIAboBOSNIA AND HERZEGOVINAbaBOTSWANAbwBOUVET ISLANDbv
    BRAZILbrBRITISH INDIAN OCEAN TERRioBRITISH VIRGIN ISLANDSvgBRUNEI DARUSSALAMbnBULGARIAbgBURKINA FASObf
    BURUNDIbiCAMBODIAkhCAMEROONcmCANADAcaCAPE VERDEcvCAYMAN ISLANDSky
    CENTRAL AFRICAN REPUBLICcfCHADtdCHILEclPEOPLE'S REPUBLIC OF CHINAcnCHRISTMAS ISLANDScxCOCOS ISLANDScc
    COLOMBIAcoCOMORASkmCONGOcgCONGO (DEMOCRATIC REPUBLIC)cdCOOK ISLANDSckCOSTA RICAcr
    COTE D IVOIREciCROATIAhrCUBAcuCYPRUScyCZECH REPUBLICczDENMARKdk
    DJIBOUTIdjDOMINICAdmDOMINICAN REPUBLICdoEAST TIMORtpECUADORec EGYPTeg
    EL SALVADORsvEQUATORIAL GUINEAgqESTONIAeeETHIOPIAetFALKLAND ISLANDSfkFAROE ISLANDSfo
    FIJIfjFINLANDfiFRANCEfrFRANCE METROPOLITANfxFRENCH GUIANAgfFRENCH POLYNESIApf
    FRENCH SOUTHERN TERRITORIEStfGABONgaGAMBIAgmGEORGIAgeGERMANYdeGHANAgh
    GIBRALTERgiGREECEgrGREENLANDglGRENADAgdGUADELOUPEgpGUAMgu
    GUATEMALAgtGUINEAgnGUINEA-BISSAUgwGUYANAgyHAITIhtHEARD & MCDONALD ISLANDhm
    HONDURAShnHONG KONGhkHUNGARYhuICELANDisINDIAinINDONESIAid
    IRAN, ISLAMIC REPUBLIC OFirIRAQiqIRELANDieISLE OF MANimISRAELilITALYit
    JAMAICAjmJAPANjpJORDANjoKAZAKHSTANkzKENYAkeKIRIBATIki
    KOREA, DEM. PEOPLES REP OFkpKOREA, REPUBLIC OFkrKUWAITkwKYRGYZSTANkgLAO PEOPLE'S DEM. REPUBLIClaLATVIAlv
    LEBANONlbLESOTHOlsLIBERIAlrLIBYAN ARAB JAMAHIRIYAlyLIECHTENSTEINliLITHUANIAlt
    LUXEMBOURGluMACAOmoMACEDONIAmkMADAGASCARmgMALAWImwMALAYSIAmy
    MALDIVESmvMALImlMALTAmtMARSHALL ISLANDSmhMARTINIQUEmqMAURITANIAmr
    MAURITIUSmuMAYOTTEytMEXICOmxMICRONESIAfmMOLDAVA REPUBLIC OFmdMONACOmc
    MONGOLIAmnMONTENEGROmeMONTSERRATmsMOROCCOmaMOZAMBIQUEmzMYANMARmm
    NAMIBIAnaNAURUnrNEPALnpNETHERLANDS ANTILLESanNETHERLANDS, THEnlNEW CALEDONIAnc
    NEW ZEALANDnzNICARAGUAniNIGERneNIGERIAngNIUEnuNORFOLK ISLANDnf
    NORTHERN MARIANA ISLANDSmpNORWAYnoOMANomPAKISTANpkPALAUpwPALESTINEps
    PANAMApaPAPUA NEW GUINEApgPARAGUAYpyPERUpePHILIPPINES (REPUBLIC OF THE)phPITCAIRNpn
    POLANDplPORTUGALptPUERTO RICOprQATARqaREUNIONreROMANIAro
    RUSSIAN FEDERATIONruRWANDArwSAMOAwsSAN MARINOsmSAO TOME/PRINCIPEstSAUDI ARABIAsa
    SCOTLANDukSENEGALsnSERBIArsSEYCHELLESscSIERRA LEONEslSINGAPOREsg
    SLOVAKIAskSLOVENIAsiSOLOMON ISLANDSsbSOMALIAsoSOMOA,GILBERT,ELLICE ISLANDSasSOUTH AFRICAza
    SOUTH GEORGIA, SOUTH SANDWICH ISLANDSgsSOVIET UNIONsuSPAINesSRI LANKAlkST. HELENAshST. KITTS AND NEVISkn
    ST. LUCIAlcST. PIERRE AND MIQUELONpmST. VINCENT & THE GRENADINESvcSUDANsdSURINAMEsrSVALBARD AND JAN MAYENsj
    SWAZILANDszSWEDENseSWITZERLANDchSYRIAN ARAB REPUBLICsyTAIWANtwTAJIKISTANtj
    TANZANIA, UNITED REPUBLIC OFtzTHAILANDthTOGOtgTOKELAUtkTONGAtoTRINIDAD AND TOBAGOtt
    TUNISIAtnTURKEYtrTURKMENISTANtmTURKS AND CALCOS ISLANDStcTUVALUtvUGANDAug
    UKRAINEuaUNITED ARAB EMIRATESaeUNITED KINGDOM (no new registrations)gbUNITED KINGDOMukUNITED STATESusUNITED STATES MINOR OUTL.IS.um
    URUGUAYuyUZBEKISTANuzVANUATUvuVATICAN CITY STATEvaVENEZUELAveVIET NAMvn
    VIRGIN ISLANDS (USA)viWALLIS AND FUTUNA ISLANDSwfWESTERN SAHARAehYEMENyeZAMBIAzmZIMBABWEzw

Test the proxy

while :; do curl -sx localhost:3128 ifconfig.io; echo ""; sleep 2; done

Credit

At GitHub, there are many repos build Docker images to provide HTTP proxy connects to the Tor network. The project is reinventing the wheels based on many of them. Remarkably:

  • y4ns0l0/docker-multi-tor creates a setup with multiple pairs of Privoxy-Tor. Having no HAProxy-like dispatcher, each Privoxy expose itself to the host as a different TCP port.
  • mattes/rotating-proxy does exactly the same job as this project. However,
    1. it utilizes Polipo as the HTTP-SOCKS proxy adapter. Polipo ceased to be maintained on 6 November 2016
    2. the base image is Ubuntu 14.04, which it too heavy for this case, and out-of-maintenance as well
    3. the main control logic is written in Ruby

Bill-of-Material

  • alpine-3.23.4
  • bash-5.3.3
  • curl-8.17.0
  • haproxy-3.2.18
  • privoxy-4.0.0
  • sed-4.9
  • tor-0.4.9.8