ZBLOG

squid 3.5.20 配合stunnel(转发http不加密到https加密的http数据包)

可以使用以下步骤来配置Squid和Stunnel,以便将非加密的HTTP流量转发到加密的HTTPS端口。

  1. 安装Squid和Stunnel

在Linux系统中,可以使用以下命令安装Squid和Stunnel:

  1. sudo apt-get install squid stunnel4
  1. 配置Squid

编辑Squid配置文件/etc/squid/squid.conf,并添加以下内容:

  1. http_port 3128 intercept
  2. acl SSL_ports port 443
  3. acl Safe_ports port 80 # http
  4. acl Safe_ports port 8080 # alternate http
  5. acl CONNECT method CONNECT
  6. http_access deny !Safe_ports
  7. http_access deny CONNECT !SSL_ports
  8. # Redirect HTTP traffic to Stunnel on port 3130.
  9. tcp_outgoing_address <IP address of your server>
  10. tcp_outgoing_address localhost out_to_stunnel
  11. # Stunnel needs to forward requests to Squid on port 3128.
  12. http_port 127.0.0.1:3130 accel defaultsite=<your_domain_name>
  13. cache_peer <your_domain_name> parent 443 0 no-query originserver login=PASSTHRU ssl sslcertck disable-pmtu-discovery name=stunnel
  14. never_direct allow all
  15. ssl_bump none localhost intercept # bypass SSL bumping for local connections
  16. sslproxy_cert_error deny all # do not allow invalid SSL certificates
  17. sslproxy_flags DONT_VERIFY_PEER # do not verify the peer's certificate

其中,

  • http_port 指定Squid监听的端口为3128,intercept参数启用拦截模式;
  • tcp_outgoing_address 指定出站流量的IP地址;
  • cache_peer 指定Stunnel的目标服务器和端口,启用SSL连接;
  • ssl_bumpsslproxy_* 配置是为了避免对HTTPS流量进行重新加密。
  1. 配置Stunnel

编辑Stunnel配置文件/etc/stunnel/stunnel.conf,并添加以下内容:

  1. client = yes
  2. foreground = yes
  3. [stunnel]
  4. accept = 127.0.0.1:443
  5. connect = <your_domain_name>:443

其中,

  • [stunnel] 是一个标识符,可以自定义;
  • accept 指定本地监听的端口为443,即HTTPS默认端口;
  • connect 指定Stunnel转发到的目标服务器和端口。
  1. 重启Squid和Stunnel服务
  1. sudo systemctl restart squid stunnel4
  1. 测试配置

在浏览器中访问任意HTTP网站,应该会被重定向到HTTPS网站。同时,在/var/log/squid/access.log中可以看到类似如下日志:

  1. 1627358323.767 10 <client_ip> TCP_MISS/302 354 GET http://www.example.com - HIER_DIRECT/<target_ip> -
  2. 1627358326.315 25 <client_ip> TCP_TUNNEL/200 14883 CONNECT www.example.com:443 - HIER_DIRECT/<target_ip> -
  3. 1627358326.317 2 <client_ip> TCP_MISS/200 4662 GET https://www.example.com/ - HIER_TUNNEL/<target_ip>

其中,

  • 第一行记录了HTTP请求被Squid拦截,返回302状态码,重定向到HTTPS地址;
  • 第二行记录了TCP_TUNNEL类型的连接,表示Stunnel已经建立与目标服务器的SSL连接;
  • 第三行记录了由Stunnel转发到Squid的HTTPS请求。

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=6516

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?