【问题标题】:Allow only specific IPs when accessing to a domain pattern in web.config访问 web.config 中的域模式时仅允许特定 IP
【发布时间】:2019-01-24 15:21:30
【问题描述】:

我需要限制特定 IP 访问我的 Web 中 Azure WebApp (IIS) 中的模式、域。配置文件。 访问时,域是 sub.admin..sub.domain.com (regexp) 必须只允许特定的 IP 范围。 我花了很多时间,但没有成功....

   <rule name="admin access" enabled="true">
      <match url="^(.+)" />
      <conditions>
         <add input="{HTTP_HOST}" type="Pattern" pattern="^(.*?[.])?admin.(.*?[.])?sub.domain.com$" />
      </conditions>
      <security>
         <ipSecurity allowUnlisted="false">
            <add ipAddress="111.111.111.111" subnetMask="255.255.255.0" allowed="true" />
         </ipSecurity>
      </security>
   </rule>

当我将此代码放入我的 web.config 时,我收到“内部服务器错误”。 有什么想法吗?

谢谢!!!!

【问题讨论】:

    标签: azure iis web-config


    【解决方案1】:

    据我所知,ipSecurity 配置可以在 url rewrite config 设置中设置,并在 url 条件中使用类型。

    这就是您收到 500 错误的原因。

    如果你想在url重写规则中检查IP,我建议你可以在条件中检查REMOTE_ADDR。

    如下:

         <rewrite>
       <rules>
        <rule name="admin access" enabled="true">
          <match url="^(.+)" />
          <conditions   logicalGrouping="MatchAll" >
            <add input="{HTTP_HOST}"   pattern="^(.*?[.])?admin.(.*?[.])?sub.domain.com$" />
            <add input="{REMOTE_ADDR}" pattern="111.111.111.111"   />
          </conditions>
         <action type="Redirect" url="the right url" />
    
        </rule>
      </rules>
    </rewrite>
    

    【讨论】:

      猜你喜欢
      • 2017-11-27
      • 1970-01-01
      • 2012-04-16
      • 2015-02-13
      • 2018-11-08
      • 2013-06-09
      • 1970-01-01
      • 1970-01-01
      • 2020-09-01
      相关资源
      最近更新 更多