nginx https透明代理_nginx正向https代理配置

一、前言

1.1 正向代理功能比较简单,但是原生nginx不支持https代理,如果访问https网站,会报错。

# nginx代理不支持http CONNECT方法:curl: (56) Received HTTP code 400 from proxy after CONNECT

1.2 为了实现对https代理的支持,需要对原有nginx源码打补丁,就可以让nginx支持CONNECT模式了。

https://github.com/chobits/ngx_http_proxy_connect_module#build-openresty

二、下载并安装openresty

shell> yum -y install lua-develshell> wget http://dlsw.91donkey.com/software/source/nginx/openresty-1.15.8.1.tar.gzshell> git clone https://github.com/chobits/ngx_http_proxy_connect_module.gitshell> tar zxf openresty-1.15.8.1.tar.gzshell> vim bundle/nginx-1.15.8/auto/cc/gcc# 将下列代码注释掉,能够减少编译后nginx二级制文件的大小,提高程序执行效率。# debugCFLAGS="$CFLAGS -g"shell> cd openresty-1.15.8.1shell> ./configure --prefix=/opt/openresty --with-http_stub_status_module --with-http_sub_module  --with-http_auth_request_module --with-http_addition_module  --add-module=/usr/local/src/ngx_http_proxy_connect_moduleshell> patch -d build/nginx-1.15.8/ -p 1 < /usr/local/src/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_101504.patchshell> gmake -j 8 && gmake installshell> echo "/opt/openresty/nginx/sbin/nginx" >> /etc/rc.d/rc.localshell> /opt/openresty/nginx/sbin/nginx# 配置nginx vim语法高亮shell> cd /usr/local/src/openresty-1.11.2.5/build/nginx-1.11.2/contrib/vim/shell> mkdir ~/.vim/ && cp -R * ~/.vim/

三、配置服务器端nginx正向代理

# 在nginx.conf中增加server{}块,具体如下: server { listen 8080; resolver 8.8.8.8; resolver_timeout 5s; 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 $scheme://$host$request_uri; proxy_set_header Host $http_host; proxy_buffers 256 4k; proxy_max_temp_file_size 0; proxy_connect_timeout 30; } access_log /export/home/logs/proxy/access.log main; error_log /export/home/logs/proxy/error.log; }

四、配置终端代理

# 在 /etc/profile 文件中增加如下三项。export proxy="http://{proxy_server_ip}:8080"export http_proxy=$proxyexport https_proxy=$proxy# 使配置生效shell> source /etc/profile

作者:龍龍小宝

原文:https://www.cnblogs.com/91donkey/p/11639311.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值