将不同的IP指向IIS7上的不同页面 [英] Direct different IP's to different pages on IIS7

查看:235
本文介绍了将不同的IP指向IIS7上的不同页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用IIS7,如何将内部专用网络 IP地址指向我的网站将外部IP地址直接发送到维护中的网站页面?

Using IIS7, how do I direct internal private network IP's addresses to my web site while I direct external IP addresses to a "site under maintenance" page?

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

So far on IIS7 I've found the section in IIS named "IPv4 Address and Domain Restrictions" and I can add the 3 internal ranges to that as an allow range. That seems easy. Now how do I direct all other traffic to a static page such as app_offline.html that I have created. (I'm not actually going to use app_offline.html because that will obviously take the app offline for internal addresses as well.)

推荐答案

您可以使用URL重写( http://www.iis.net/download/URLRewrite ) 为了那个原因。
然后你可以使用以下内容删除web.config:

You can use URL Rewrite (http://www.iis.net/download/URLRewrite) for that. Then you can drop a web.config with the contents like:

<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>

它的基本做法是仅在内容不是站点的情况下才应用此规则-constructionpage(防止无限重定向),只有在IP地址不是来自192.168.XXX.XXX(并且不是localhost)时才应用此项。

What it basically does is to only apply this rule if the content is not already the "site-under-construction" page (to prevent infinite redirects), and only apply this if the IP-address is not coming from 192.168.XXX.XXX (and is not localhost).

否则它会让他们进入他们要求的任何页面。

Otherwise it will let them come through to whatever page they requested.

请注意,这不应该用作安全机制,因为Remote Addr可能会被欺骗,但听起来像对于你的场景,它应该没问题。

Note that this should not be use as a security mechanism since Remote Addr could be spoofed, but sounds like for your scenario it should be fine.

这篇关于将不同的IP指向IIS7上的不同页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆