分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

手头没证书,如何给https做代理?NGINX TCP转发

发布时间:2023-09-06 01:48责任编辑:郭大石关键词:http

线上的一个海外充值接口(https)经常因我朝网络问题中断,想借助hk的机器做个https反向代理又没证书。

一开始

一开始想到的办法是借助NGINX的tcp转发进行代理:

编译NGINX时加入 --with-stream选项,

upstream backend { ??server xxxxxx.com:443 ;}server { ???listen 443; ???proxy_pass backend; ???proxy_connect_timeout 15s; ???proxy_timeout 15s; ???proxy_next_upstream_timeout 15s; ??error_log /data/logs/tcp_xxxxxx.com.log info;}

服务器通过绑定host,将https://xxxxxx.com的访问请求到中转机再反向到实际的海外服务器确实也ok

不过这里也将面临一个问题:443端口只能被https://xxxxxx.com占用,无法给其他域名的代理提供作用

后来

如果我想https://xxxxxx.com和https://yyyyyy.com都借助这台机器代理呢?NGINX的stream_ssl_preread_module可以解决这个问题

NGINX(1.11+),编译时加入:--with-stream--with-stream_ssl_preread_module 两个选项,

然后配置:

map $ssl_preread_server_name $backend_pool { ???xxxxxx.com ???xxx; ???yyyyyy.com ???yyy;}upstream xxx{ ???server xxxxxx.com :443;}upstream yyy{ ???server yyyyyy.com:443;}server { ???listen 443; ???ssl_preread on; ???resolver 8.8.8.8; ???proxy_pass $backend_pool; ???proxy_connect_timeout 15s; ???proxy_timeout 15s; ???proxy_next_upstream_timeout 15s; ???error_log /data/logs/tcp_xxxxxx-yyyyyy.com.log info;}

这样就可以给https://xxxxxx.com 和https://yyyyyy.com两个域名做tcp层的代理了,其他域名如果也绑host过来就会被403掉。

这里其实是利用了NGINX的TCP转发做了SNI 反代,与普通的http/http的区别在于,TCP转发只是四层转发不需要证书:

  • SNI 反代:tcp 镜像流复制
  • 普通的 https 反向:需要挂证书二次加解密

在很多公司有内外网隔离得情况下,内网研发人员的一些开发工具需要访问https镜像仓库站点时(例如:Gradle Plugin),就可以借助SNI反向实现

参考:http://nginx.org/en/docs/stream/ngx_stream_ssl_preread_module.html

手头没证书,如何给https做代理?NGINX TCP转发

原文地址:https://www.cnblogs.com/wshenjin/p/8719016.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved