Nginx正向代理http、https

https://github.com/chobits/ngx_http_proxy_connect_module

1、按照说明文档下载对应的nginx patch、module,编译安装nginx

$ wget http://nginx.org/download/nginx-1.14.2.tar.gz
$ tar -xzvf nginx-1.14.2.tar.gz
$ cd nginx-1.14.2/

// 参考说明文档下载适合此版本nginx的patch
$ wget https://github.com/chobits/ngx_http_proxy_connect_module/blob/master/patch/proxy_connect_1014.patch
// 下载ngx_http_proxy_connect_module,解压到此目录
$ ll
-rw-r--r-- 1 root root    376 Jun 15 11:15 Makefile
drwxr-xr-x 5 root root   4096 Jun 15 11:13 ngx_http_proxy_connect_module-master
-rw-r--r-- 1 root root   9849 Jun 15 11:13 proxy_connect_1014.patch

$ patch -p1 < proxy_connect_1014.patch
$ ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=ngx_http_proxy_connect_module-master 
$ make && make install

2、nginx配置

 server {
     listen                         3128;

     # dns resolver used by forward proxying
     resolver                       8.8.8.8;

     # forward proxy for CONNECT request
     proxy_connect;
     proxy_connect_allow            443 563; #许可https和nntps协议通过
     proxy_connect_connect_timeout  10s;
     proxy_connect_read_timeout     10s;
     proxy_connect_send_timeout     10s;

     # forward proxy for non-CONNECT request
     location / {
         proxy_pass http://$host;
         proxy_set_header Host $host;
     }
 }

3、测试

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

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值