如何透過Python自行架設代理伺服器 (Proxy Server)

Posted in :

由於IP 被擋, 需要暫時使用跳板來換IP, 先申請一台虛擬主機, 在 Linux 的環境下執行下列2行指令, 可以取得自己的 proxy server:

python -m pip install pproxy
pproxy

pproxy 官方網站:
https://github.com/qwj/python-proxy

pproxy 執行後, 監聽的port 預設會在 8080.

pproxy 詳細使用方式:

$ pproxy -h
usage: pproxy [-h] [-l LISTEN] [-r RSERVER] [-ul ULISTEN] [-ur URSERVER]
              [-b BLOCK] [-a ALIVED] [-v] [--ssl SSLFILE] [--pac PAC]
              [--get GETS] [--sys] [--test TESTURL] [--version]

Proxy server that can tunnel among remote servers by regex rules. Supported
protocols: http,socks4,socks5,shadowsocks,shadowsocksr,redirect,pf,tunnel

optional arguments:
  -h, --help        show this help message and exit
  -l LISTEN         tcp server uri (default: http+socks4+socks5://:8080/)
  -r RSERVER        tcp remote server uri (default: direct)
  -ul ULISTEN       udp server setting uri (default: none)
  -ur URSERVER      udp remote server uri (default: direct)
  -b BLOCK          block regex rules
  -a ALIVED         interval to check remote alive (default: no check)
  -s {fa,rr,rc,lc}  scheduling algorithm (default: first_available)
  -v                print verbose output
  --ssl SSLFILE     certfile[,keyfile] if server listen in ssl mode
  --pac PAC         http PAC path
  --get GETS        http custom {path,file}
  --sys             change system proxy setting (mac, windows)
  --test TEST       test this url for all remote proxies and exit
  --version         show program's version number and exit

Online help: <https://github.com/qwj/python-proxy>

為什麼要使用 proxy? 而不是使用 linux 的 squid?

因為 python 使用上很簡單, 而且開放原始碼, 要修改也相對容易, 相依性的問題上也相對較少。

使用 python 的話, 就跨平台, 不一定限定要在 linux 的伺服器上。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *