AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 442708
Accepted
Dylan Beattie
Dylan Beattie
Asked: 2012-10-27 06:33:08 +0800 CST2012-10-27 06:33:08 +0800 CST 2012-10-27 06:33:08 +0800 CST

我可以在 Varnish 服务器上使用 iptables 将 HTTPS 流量转发到特定服务器吗?

  • 772

我们使用 Varnish 作为我们的前端网络缓存和负载平衡器,所以我们在我们的开发环境中有一个 Linux 服务器,在一对 Windows 2008 IIS Web 服务器上运行带有一些基本缓存和负载平衡规则的 Varnish。

我们有一个指向 *.development 的通配符 DNS 规则,因此我们可以浏览http://www.mysite.com.development、http://www.othersite.com.development等。问题是由于 Varnish 无法处理 HTTPS 流量,我们无法访问https://www.mysite.com.development/

对于开发/测试,我们不需要任何加速或负载平衡——我只需要告诉这个盒子充当一个哑代理,并将端口 443 上的任何传入请求转发到特定的 IIS 服务器。我怀疑 iptables 可能会提供解决方案,但自从我编写 iptables 规则以来已经有很长一段时间了。一些最初的黑客攻击让我达到了

iptables -F
iptables -A INPUT -p tcp -m tcp --sport 443 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --dport 443 -j ACCEPT
iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to 10.0.0.241:443
iptables -t nat -A POSTROUTING -p tcp -d 10.0.0.241 --dport 443 -j MASQUERADE
iptables -A INPUT -j LOG --log-level 4 --log-prefix 'PreRouting '
iptables -A OUTPUT -j LOG --log-level 4 --log-prefix 'PostRouting '
iptables-save > /etc/iptables.rules

(其中 10.0.0.241 是托管 HTTPS 网站的 IIS 框),但这似乎不起作用。

澄清一下 - 我意识到 HTTPS 代理/缓存存在安全隐患 - 我正在寻找的是完全透明的 IP 流量转发。我不需要解密、缓存或检查任何数据包;我只希望端口 443 上的任何内容都通过 Linux 机器流到它后面的 IIS 机器,就好像 Linux 机器根本不在那里一样。

任何帮助感激不尽......

编辑:包括完整的 iptables 配置脚本。

iis
  • 2 2 个回答
  • 1956 Views

2 个回答

  • Voted
  1. Best Answer
    Bruno Vieira
    2012-10-27T07:45:14+08:002012-10-27T07:45:14+08:00

    这是将流量从一个主机重定向到特定端口中的另一台主机的方法,请注意,对端口 443 的每个请求都将重定向到您在 iptables 上指向的主机:

    1)开放443端口流量:

    iptables -A INPUT -p tcp -m tcp --sport 443 -j ACCEPT
    iptables -A OUTPUT -p tcp -m tcp --dport 443 -j ACCEPT
    

    2) 添加特定规则以重定向传入和传出数据

    iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to ip.listenig.to:443
    iptables -t nat -A POSTROUTING -p tcp -d ip.listening.to --dport 443 -j MASQUERADE
    

    3)或者,您可以重定向来自特定主机的流量,例如:

     iptables -t nat -A PREROUTING -s ip._not_.listening -p tcp --dport 443 -j DNAT --to-destination ip.listening.to:443
    

    (如果你想在你网络下的其他客户端中处理端口 443,此步骤特别有用)

    4)通知内核你将接受ip转发

    编辑文件/etc/sysctl.conf(或适合您的发行版的文件)并附加(或更改)

    net.ipv4.ip_forward=1
    

    然后发出命令

    sysctl -p /etc/sysctl.conf (or the file that suits your distro)
    

    我希望它有所帮助

    • 3
  2. Dylan Beattie
    2012-10-30T01:49:42+08:002012-10-30T01:49:42+08:00

    好的,这是完整的解决方案——这是在 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64) 上

    首先,我必须通过编辑 /etc/sysctl.conf 并取消注释行来启用 ip4 端口转发:

    net.ipv4.ip_forward=1
    

    然后我必须运行/sbin/sysctl -p才能使此更改生效。

    接下来配置(和捕获)iptables规则脚本:

    # flush any existing rules 
    iptables -F
    # Configure iptables to allow incoming traffic on port 443
    iptables -A INPUT -p tcp -m tcp --sport 443 -j ACCEPT
    # Configure iptables to allow outgoing traffic on port 443
    iptables -A OUTPUT -p tcp -m tcp --dport 443 -j ACCEPT
    # Configure iptables to NAT incoming 443 traffic to 10.0.0.241:443
    iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to 10.0.0.241:443
    # Configure iptables to route responses from these requests back to the original requester
    iptables -t nat -A POSTROUTING -p tcp -d 10.0.0.241 --dport 443 -j MASQUERADE
    # Dump the ruleset and save it into the file /etc/iptables.rules
    iptables-save > /etc/iptables.rules
    

    最后,为了使更改在重新启动后持续存在,我必须编辑 /etc/network/interfaces:

    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    auto eth0
    iface eth0 inet static
        address 10.0.0.240
        netmask 255.255.255.0
        network 10.0.0.0
        broadcast 10.0.0.255
        gateway 10.0.0.1
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 192.168.0.11
        dns-search spotmain.com
    
        # The next line was added to enable iptables rules on system restart
        pre-up iptables-restore < /etc/iptables.rules
    
    • 3

相关问题

  • 2003 Server企业版不能运行ASP.NET应用程序?

  • 启用集成 Windows 身份验证时,ASP(经典)在哪个帐户下运行?

  • 是否有一种简单的方法可以生成有关 IIS 中“死”文件的报告?

  • IIS 7 中的 URL 重写

  • 对于 ASP.Net 应用程序,Windows 64 位相对于 32 位的主要优势是什么?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve