Azure网站IP限制

Flo*_*der 5 ip azure cloudflare azure-web-sites

我有一个Azure网站,我只用于开发和测试,因此我想限制除了我自己以外的所有人访问它.根据这篇博文文章,现在这是正式支持的,所以我尝试将其添加到我的web.config文件中:

<system.webServer>
    <security>
        <ipSecurity allowUnlisted="false" denyAction="NotFound">
            <add allowed="true" ipAddress="1.2.3.4" />
        </ipSecurity>
    </security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

对于ipAddress属性,我必须使用我的互联网连接的IP地址吗?所以我去了http://www.whatismyip.com/并复制了地址,但现在我的网站只是阻止所有请求,允许规则无效.

我错过了什么?

更新:日志文件显示Web服务器看到的IP不是实际客户端的IP,而是介于两者之间的代理(Cloudflare).所以我尝试通过添加来解决这个enableProxyMode="true"问题,遗憾的是这不能解决我的问题.有关如何获得IP限制以使用Cloudflare的任何想法?

Flo*_*der 7

万一有人试图使用Cloudflare设置IP限制:解决方案不仅要将您的IP添加到白名单,还要添加所有Cloudflare IP(从这里获取).

<system.webServer>
    <security>
        <ipSecurity enableProxyMode="true" allowUnlisted="false" denyAction="NotFound">
            <!-- YOUR IP -->
            <add allowed="true" ipAddress="1.2.3.4" />
            <!-- CLOUDFLARE -->
            <add allowed="true" ipAddress="199.27.128.0" subnetMask="255.255.248.0" />
            <add allowed="true" ipAddress="173.245.48.0" subnetMask="255.255.240.0" />
            <add allowed="true" ipAddress="103.21.244.0" subnetMask="255.255.252.0" />
            <add allowed="true" ipAddress="103.22.200.0" subnetMask="255.255.252.0" />
            <add allowed="true" ipAddress="103.31.4.0" subnetMask="255.255.252.0" />
            <add allowed="true" ipAddress="141.101.64.0" subnetMask="255.255.192.0" />
            <add allowed="true" ipAddress="108.162.192.0" subnetMask="255.255.192.0" />
            <add allowed="true" ipAddress="190.93.240.0" subnetMask="255.255.240.0" />
            <add allowed="true" ipAddress="188.114.96.0" subnetMask="255.255.240.0" />
            <add allowed="true" ipAddress="197.234.240.0" subnetMask="255.255.252.0" />
            <add allowed="true" ipAddress="198.41.128.0" subnetMask="255.255.128.0" />
            <add allowed="true" ipAddress="162.158.0.0" subnetMask="255.254.0.0" />
            <add allowed="true" ipAddress="104.16.0.0" subnetMask="255.240.0.0" />
        </ipSecurity>
    </security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)