【问题标题】:Direct different IP's to different pages on IIS7将不同的 IP 定向到 IIS7 上的不同页面
【发布时间】:2011-03-10 09:15:53
【问题描述】:

使用 IIS7,我如何将内部private network IP 地址定向到我的网站,而将外部 IP 地址定向到“正在维护的站点”页面?

到目前为止,在 IIS7 上,我在 IIS 中找到了名为“IPv4 地址和域限制”的部分,我可以将 3 个内部范围添加到其中作为允许范围。这似乎很容易。现在如何将所有其他流量引导到我创建的静态页面,例如 app_offline.html。 (我实际上不会使用 app_offline.html,因为这显然会使应用程序离线以获取内部地址。)

【问题讨论】:

  • 更适合serverfault.comIMO
  • 这些是部署 Web 应用程序并配置 IIS7 的开发人员,因此在考虑 SO 或 SF 时,我认为这是更好的地方。

标签: iis-7 web-config ip-address asp.net-routing


【解决方案1】:

您可以为此使用 URL 重写 (http://www.iis.net/download/URLRewrite)。 然后你可以删除一个 web.config,其内容如下:

<configuration>
  ...
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="External IP" stopProcessing="true">
          <match url="site-under-construction\.htm" negate="true" />
          <conditions>
            <add input="{REMOTE_ADDR}" pattern="192\.168\.\d+\.\d+" ignoreCase="false" negate="true" />
            <add input="{REMOTE_ADDR}" pattern="::1" ignoreCase="false" negate="true" />
            <add input="{REMOTE_ADDR}" pattern="127\.0\.0\.1" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Redirect" url="/site-under-construction.htm" redirectType="Found" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
  ...
</configuration>

它的基本作用是仅在内容还不是“正在建设的站点”页面时应用此规则(以防止无限重定向),并且仅在 IP 地址不是来自 192.168 时应用此规则。 XXX.XXX(并且不是本地主机)。

否则它将让他们进入他们请求的任何页面。

请注意,这不应该用作安全机制,因为远程地址可能会被欺骗,但听起来对于您的场景来说应该没问题。

【讨论】:

    猜你喜欢
    • 2010-10-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    • 2020-09-20
    • 2014-08-13
    相关资源
    最近更新 更多