nginx正向代理、tinyproxy和goproxy代理

nginx 正向代理

1. 安装 openresty

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
yum -y install patch

wget https://openresty.org/download/openresty-1.19.9.1.tar.gz
tar -zvxf openresty-1.19.9.1.tar.gz
cd openresty-1.19.9.1/
mkdir modules/
cd modules/
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
cd ..
./configure \
--add-module=/root/openresty-1.19.9.1/modules/ngx_http_proxy_connect_module \
--prefix=/root/software/openresty \
--with-luajit \
--without-http_redis2_module \
--with-http_iconv_module \
--with-http_postgres_module \
--with-mail \
--with-stream
patch -d build/nginx-1.19.9/ -p1 < /root/openresty-1.19.9.1/modules/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch
gmake && gmake install

2. 配置代理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
server {
listen 1080;
access_log logs/proxy.log;
resolver 114.114.114.114; #指定DNS服务器IP地址
server_name proxy.ifan.tutulis.com;
proxy_connect;
proxy_connect_allow 80 443;
proxy_connect_connect_timeout 10s;
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
# forward proxy for non-CONNECT request
location / {
# proxy_pass $scheme://$http_host$request_uri
proxy_pass http://$host;
proxy_set_header Host $host;

proxy_buffers 256 4k;
proxy_max_temp_file_size 0;

proxy_connect_timeout 10s;
}
}

3. 测试代理

1
curl https://www.baidu.com -v -x 127.0.0.1

tinyproxy

使用Docker搭建

1
docker run -d --name tinyproxy --restart always -p 8888:8888 stilleshan/tinyproxy

BasicAuth 加密

1
docker run -d --name tinyproxy --restart always -p 8888:8888 -v /opt/tinyproxy/tinyproxy.conf:/etc/tinyproxy/tinyproxy.conf stilleshan/tinyproxy

测试

1
curl -x https://IP:8888 cip.cc

Goproxy

官网
Github

下载使用

1
2
3
4
mkdir proxy && cd proxy
wget https://github.91chi.fun//https://github.com//snail007/goproxy/releases/download/v11.8/proxy-linux-amd64.tar.gz
tar -zxvf proxy-linux-amd64.tar.gz
rm ._*

配置文件启动

创建 configfile.txt

1
2
3
4
http  
-t tcp
-p :33080
--forever

启动

1
proxy @configfile.txt

守护状态

1
proxy http -p ":9090" --forever --log proxy.log --daemon