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

 

你可能感兴趣的:(Nginx)