ZBLOG

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

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

  1. 安装Squid和Stunnel

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

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

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

http_port 3128 intercept
acl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 8080        # alternate http
acl CONNECT method CONNECT
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports

# Redirect HTTP traffic to Stunnel on port 3130.
tcp_outgoing_address <IP address of your server>
tcp_outgoing_address localhost out_to_stunnel

# Stunnel needs to forward requests to Squid on port 3128.
http_port 127.0.0.1:3130 accel defaultsite=<your_domain_name>

cache_peer <your_domain_name> parent 443 0 no-query originserver login=PASSTHRU ssl sslcertck disable-pmtu-discovery name=stunnel

never_direct allow all

ssl_bump none localhost intercept     # bypass SSL bumping for local connections
sslproxy_cert_error deny all          # do not allow invalid SSL certificates 
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,并添加以下内容:

client = yes
foreground = yes

[stunnel]
accept = 127.0.0.1:443
connect = <your_domain_name>:443

其中,

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

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

1627358323.767     10 <client_ip> TCP_MISS/302 354 GET http://www.example.com - HIER_DIRECT/<target_ip> -
1627358326.315     25 <client_ip> TCP_TUNNEL/200 14883 CONNECT www.example.com:443 - HIER_DIRECT/<target_ip> -
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://sdn.0voice.com/?id=1462

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

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

联系我们

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

微信号:3007537140

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

关注我们
x

注册

已经有帐号?