系统环境
- Ubuntu Server 18.04 LTS
安装依赖
$ apt install -y libpcre3-dev zlib1g-dev libssl-dev
设置工作目录
$ mkdir -p /data
$ cd /data
下载模块
$ git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
下载 Nginx
本文中以 Nginx 1.14.0 版本为例
$ wget http://nginx.org/download/nginx-1.14.0.tar.gz
$ tar -xzf nginx-1.14.0.tar.gz
应用 Nginx 补丁
根据本文上述 Nginx 版本为 1.14.0,故选择补丁文件:proxy_connect_1014.patch,更多版本请查看模块目录下 patch 文件夹
$ cd nginx-1.14.0
$ patch -p1 < /data/ngx_http_proxy_connect_module/patch/proxy_connect_1014.patch
编译安装
$ ./configure --user=www-data --group=www-data --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-threads --add-module=/data/ngx_http_proxy_connect_module
$ make && make install
配置 VHOST
$ nano /usr/local/nginx/conf/nginx.conf
server {
listen 10101 default_server;
# dns resolver used by forward proxying
resolver 8.8.8.8;
resolver_timeout 3s;
# forward proxy for CONNECT request
proxy_connect;
# specifies a list of port numbers to which the proxy CONNECT method may connect.
# the default ports are 443 and 563. only the listed ports can make connections.
proxy_connect_allow 443 563;
index index.html;
# forward proxy for non-CONNECT request
location / {
proxy_pass http://$http_host$request_uri;
proxy_set_header Host $http_host;
}
}
CURL 测试
$ curl https://www.baidu.com -svo /dev/null -x proxy_url:10101
Git 测试
首先配置 Git 代理服务器:
$ git config --global http.proxy "http://proxy_url:10101"
$ git config --global https.proxy "http://proxy_url:10101"
修改后,可通过查看当前用户目录下 .gitconfig 查看配置情况
$ nano ~/.gitconfig
撤销 Git 代理:
$ git config --global --unset http.proxy
$ git config --global --unset https.proxy
$ git config --global --unset core.gitproxy
Yarn 测试
首先配置 Yarn 代理服务器:
$ yarn config set proxy http://proxy_url:10101
$ yarn config set https-proxy http://proxy_url:10101
查看配置修改情况:
$ yarn config list
开始测试安装依赖,并监视代理服务器连接情况,可通过在代理服务器上安装 nethogs
$ yarn install --network-timeout 1000000
撤销 Yarn 代理:
$ yarn config delete proxy
$ yarn config delete https-proxy
Reference URL:
- https://www.louxiaohui.com/2019/09/08/nginx-as-forward-proxy-for-https/
- https://www.alibabacloud.com/blog/how-to-use-nginx-as-an-https-forward-proxy-server_595799
- https://github.com/chobits/ngx_http_proxy_connect_module