nginx 正向代理http和https

nginx正向代理默认只支持http,不支持https,需借助第三方模块“ngx_http_proxy_connect_module”来实现(https://github.com/chobits/ngx_http_proxy_connect_module)

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel

patch -p1 </newData/soft/ngx_http_proxy_connect_module-master/patch/proxy_connect_rewrite_1018.patch

./configure --prefix=/usr/local/nginx2 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-threads --add-module=/newData/soft/ngx_http_proxy_connect_module-master

make & make install

nginx配置同时支持http和https

server {
     resolver 114.114.114.114 8.8.8.4 8.8.8.8; #多开几个,否则部分网站打不开
     listen 109;
     proxy_connect;
     proxy_connect_allow            all;		#支持不同端口https
     proxy_ignore_client_abort   on;
     location / {
	 	fastcgi_param REQUEST_METHOD  $request_method;
	 	fastcgi_param CONTENT_TYPE    $content_type;
	 	fastcgi_param CONTENT_LENGTH  $content_length;
	 	proxy_http_version 1.1;
	 	proxy_buffering    off;
	 	proxy_set_header   Cookie       $http_cookie;
	 	proxy_set_header   X-Real-IP $remote_addr;
	 	proxy_set_header   X-Scheme $scheme;
	 	proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
	 	proxy_ssl_server_name on;	 	
	 	proxy_pass              $scheme://$http_host$request_uri;
	 	proxy_set_header   Host $http_host; #$http_host; #$host;
	 	proxy_set_header Content-Type    $content_type;
	 	proxy_send_timeout 60000;
	 	proxy_read_timeout 60000;
	 	proxy_next_upstream error timeout invalid_header http_502;
     }
}

如果碰到这种错误

make[1]: *** No rule to make target ‘objs/addon/ngx_http_mytest2/ngx_http_mytest2_module.o’, needed by ‘objs/nginx’. Stop.

1.确认上面安装的nginx模块是否都正确

2.ngx_http_proxy_connect_module-master 如果是从windows上拷过去,可能会有些文件不正确,需仔细确认

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值