【原创】让nginx正向代理同时支持代理http和https请求

blogdaren 2018-12-19 抢沙发 277人次

问题背景:

默认情况下,nginx正向代理是支持代理http请求的,但是却不支持代理https请求,怎么办?

解决方案:

patch一个补丁包到nginx内核,下载补丁:ngx_http_proxy_connect_module

安装依赖【ubuntu】:

# sudo apt-get install libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev

patch步骤:

# wget http://nginx.org/download/nginx-1.9.2.tar.gz
# tar xzvf nginx-1.9.2.tar.gz
# cd nginx-1.9.2
# patch -p1 < /path/to/ngx_http_proxy_connect_module/proxy_connect.patch
# ./configure --add-module=/path/to/ngx_http_proxy_connect_module
# make && make install

配置文件:

server {
    resolver 114.114.114.114;
    resolver_timeout 10s;
    listen       7777;
    proxy_connect;
    proxy_connect_allow            443 563;                                                                                                     
    proxy_connect_connect_timeout  10s;
    proxy_connect_read_timeout     10s;
    proxy_connect_send_timeout     10s;

    location / {
      proxy_pass http://$host;
      proxy_set_header Host $host;
      proxy_buffers 256 4k;
      proxy_max_temp_file_size 0;
      proxy_connect_timeout 30;
    }
}

注意事项:

1、多看 README.md;

2、支持如下nginx版本:

* 1.12.1 (stable version of 1.12.x)
* 1.10.3 (stable version of 1.10.x)
* 1.9.2 (stable version of 1.9.x)
* 1.8.1 (stable version of 1.8.x)
* 1.6.3 (stable version of 1.6.x)
* 1.4.7 (stable version of 1.4.x)


版权声明:除非注明,本文由( blogdaren )原创,转载请保留文章出处。

本文链接:【原创】让nginx正向代理同时支持代理http和https请求

发表评论:

您的昵称:
电子邮件:
个人主页: