2017-06-21 73 views
0

我已经创建了SQL Server和数据库,Web应用程序,已发布的网站和数据库并进入网站的登录屏幕。ARM模板 - 为Web应用程序创建SQL Server防火墙规则

当我登录时,我收到一个包含当前不允许访问新创建的SQL Server的Web应用程序的IP地址的500。

我非常想收获分配的IP地址(怀疑它是AZURE内部IP地址)以在模板中创建防火墙规则。

我成功地为存储帐户密钥和数据库连接字符串添加应用设置。这些工作很好。

非常令人沮丧的是无法找到任何对网站内部IP的引用。我已经尝试了Azure门户中的对象浏览器。

意见建议谢谢! Andy

回答

0

如果您正在使用Azure SQL,关于如何设置Azure数据库防火墙,请参阅document

非常令人沮丧的是,无法找到任何对网站内部IP的引用?

如果想让Azure的服务来访问SQL Azure的数据库,我们只需要设置

允许访问Azure服务上。的默认值为

enter image description here

我们也能拿的出站IP地址,我们可以从蔚蓝的资源(https://resources.azure.com/)让他们再outboundIpAddresses添加到允许的IP列表中的SQL Azure的防火墙规则。

enter image description here

注意:对于Web应用程序天青的outboundIpAddresses不是静态IP地址,当我们重新启动Web应用程序或Web应用程序更改服务计划,他们可以改变。

如果我们想通过ARM模板添加防火墙规则,我们可以使用下面的演示代码:

{ 
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { 
     "testfirewallAdminLogin": { 
      "type": "string", 
      "minLength": 1 
     }, 
     "testfirewallAdminLoginPassword": { 
      "type": "securestring" 
     }}, 
    "variables": { 
     "testfirewallName": "[concat('testfirewall', uniqueString(resourceGroup().id))]"}, 
    "resources": [ 
     { 
      "name": "[variables('testfirewallName')]", 
      "type": "Microsoft.Sql/servers", 
      "location": "[resourceGroup().location]", 
      "apiVersion": "2014-04-01-preview", 
      "dependsOn": [ ], 
      "tags": { 
       "displayName": "testfirewall" 
      }, 
      "properties": { 
       "administratorLogin": "[parameters('testfirewallAdminLogin')]", 
       "administratorLoginPassword": "[parameters('testfirewallAdminLoginPassword')]" 
      }, 
      "resources": [ 
       { 
        "name": "AllowAllWindowsAzureIps", 
        "type": "firewallrules", 
        "location": "[resourceGroup().location]", 
        "apiVersion": "2014-04-01-preview", 
        "dependsOn": [ 
         "[resourceId('Microsoft.Sql/servers', variables('testfirewallName'))]" 
        ], 
       "properties": { 
        "startIpAddress": "x.x.x.x", 
        "endIpAddress": "x.x.x.x" 
       } 
       } 
      ] 
     }], 
    "outputs": { 

    } 
} 
相关问题