Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure网站IP限制_Azure_Ip_Azure Web App Service_Cloudflare - Fatal编程技术网

Azure网站IP限制

Azure网站IP限制,azure,ip,azure-web-app-service,cloudflare,Azure,Ip,Azure Web App Service,Cloudflare,我有一个Azure网站,我只用于开发和测试,因此我想限制除我之外的所有人访问它。 根据这一点,现在这是官方支持的,因此我尝试将其添加到我的web.config文件中: <system.webServer> <security> <ipSecurity allowUnlisted="false" denyAction="NotFound"> <add allowed="true" ipAddress="1.2

我有一个Azure网站,我只用于开发和测试,因此我想限制除我之外的所有人访问它。 根据这一点,现在这是官方支持的,因此我尝试将其添加到我的web.config文件中:

<system.webServer>
    <security>
        <ipSecurity allowUnlisted="false" denyAction="NotFound">
            <add allowed="true" ipAddress="1.2.3.4" />
        </ipSecurity>
    </security>
</system.webServer>

并复制了地址,但现在我的网站只是阻止所有请求,允许规则没有任何效果

我错过什么了吗


更新:日志文件显示web服务器看到的IP不是实际客户端的IP,而是介于两者之间的代理(Cloudflare)。因此,我试图通过添加
enableProxyMode=“true”
来解决这个问题,不幸的是,这并不能解决我的问题。有没有关于如何让IP限制与Cloudflare一起使用的想法?

以防有人试图使用Cloudflare设置IP限制:解决方案不仅是将您的IP添加到白名单,还包括所有Cloudflare IP(取自)


自Azure SDK 2.3以来,可以使用访问控制列表(ACL)为您的云服务应用IP限制

只需将ACL添加到您的ServiceConfiguration.Cloud.cscfg

<NetworkConfiguration>
    <AccessControls>
        <AccessControl name="test">
            <Rule action="permit" description="test" order="100" remoteSubnet="xxx.xxx.xxx.xxx/32" />
            <Rule action="deny" description="test" order="200" remoteSubnet="0.0.0.0/0" />
        </AccessControl>
    </AccessControls>
    <EndpointAcls>
        <EndpointAcl role="WebRoleName" endPoint="Endpoint1" accessControl="test" />
    </EndpointAcls>
</NetworkConfiguration>

不是完整的答案,只是以有用的复制/粘贴格式发布了一个稍微更新的CloudFlare IP列表。有关用法,请参阅公认的答案

    <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="104.16.0.0" subnetMask="255.240.0.0" />
    <add allowed="true" ipAddress="108.162.192.0" subnetMask="255.255.192.0" />
    <add allowed="true" ipAddress="131.0.72.0" subnetMask="255.255.252.0" />
    <add allowed="true" ipAddress="141.101.64.0" subnetMask="255.255.192.0" />
    <add allowed="true" ipAddress="162.158.0.0" subnetMask="255.254.0.0" />
    <add allowed="true" ipAddress="172.64.0.0" subnetMask="255.248.0.0" />
    <add allowed="true" ipAddress="173.245.48.0" subnetMask="255.255.240.0" />
    <add allowed="true" ipAddress="188.114.96.0" subnetMask="255.255.240.0" />
    <add allowed="true" ipAddress="190.93.240.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="199.27.128.0" subnetMask="255.255.248.0" />


您的ipAddress属性是正确的。您确定这正是web.config中的内容吗?您现在的配置(针对我的IP更改)工作正常。如果此配置正确,则进入站点的“配置”页面并打开WEB服务器日志文件系统。然后,再次尝试访问您的站点并查看日志,查看正在记录的客户端IP。感谢您的提示!我会检查我的日志文件,但是公众是否可以再次访问该网站?也就是说,假设所有流量都通过Cloudflare访问该站点,那么这如何阻止其他人呢?Cloudflare在原始客户端的IP中添加了一个
X-Forwarded-For
HTTP头,并且
enableProxyMode=“true”
告诉Web服务器也要检查该头中的有效IP。让我非常惊讶的是,这实际上工作得非常好。只要您启用ProxyMode,那么它似乎只将CF IP作为代理头,不允许它们实际访问,而是使用它们来计算原始请求IP。我将发布一个更新的IP列表作为一个单独的答案(建议的编辑队列已经满了)。这很好-谢谢!如果您使用CloudFlare Access,则执行此操作非常重要。这适用于云服务,但不适用于Azure Web应用
    <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="104.16.0.0" subnetMask="255.240.0.0" />
    <add allowed="true" ipAddress="108.162.192.0" subnetMask="255.255.192.0" />
    <add allowed="true" ipAddress="131.0.72.0" subnetMask="255.255.252.0" />
    <add allowed="true" ipAddress="141.101.64.0" subnetMask="255.255.192.0" />
    <add allowed="true" ipAddress="162.158.0.0" subnetMask="255.254.0.0" />
    <add allowed="true" ipAddress="172.64.0.0" subnetMask="255.248.0.0" />
    <add allowed="true" ipAddress="173.245.48.0" subnetMask="255.255.240.0" />
    <add allowed="true" ipAddress="188.114.96.0" subnetMask="255.255.240.0" />
    <add allowed="true" ipAddress="190.93.240.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="199.27.128.0" subnetMask="255.255.248.0" />