[关闭]
@zhouyy 2018-03-16T06:55:41.000000Z 字数 5853 阅读 666

1.2 Configure website-Application Settings

azure


1 general settings

  1. PS C:\Users\Administrator.USER-20170626GN> $wsName
  2. yy-test-web
  3. PS C:\Users\Administrator.USER-20170626GN> Set-AzureWebsite $wsName -WebSocketsEnabled $true

2 app settings

app settings can be anything, such as URL to a websevice

app settings and connection string 都可以被app 以环境变量的方式获得

环境变量构造:
- Name of environment var = constant str + key name
for connstr:
=SQLAZURECONNSTR_/SQLCONNSTR_/MYSQLCONNSTR_/CUSTOMECONNSTR_ + testAppConnStr
=SQLAZURECONNSTR_testAppConnStr
for app setting:
= constant str + key name
=APPSETTING_+webServiceURL

  1. PS C:\Users\Administrator.USER-20170626GN> $settings = New-Object Hashtable
  2. PS C:\Users\Administrator.USER-20170626GN> $settings["YY-test-web-hr-url"]= "https://yy-test-web/hr"
  3. PS C:\Users\Administrator.USER-20170626GN> Set-AzureWebsite -Name $wsName -AppSettings $settings

3 connection strings

option 1: store a connection string as a site setting
option 2: store the settings in app configure file like Web.configPhp.ini

option 1 is preferred. app 可以在运行时作为环境变量获取 connection string, 这样做更加安全,避免了在app 配置文件中存储敏感信息。

以k/v的形式被存储

  1. Key = "testAppConnStr"
  2. Value = "Server=tcp: ;Database= ;User ID= "

@{} hash k/v

  1. PS C:\Users\Administrator.USER-20170626GN> $connStrs = (@{Name="yytestwebdb"; Type ="SQLAzure"; ConnectionString="Server=tcp:foodsafety.database.chinacloudapi.cn,1433;Initial Catalog=food-trace"})
  2. PS C:\Users\Administrator.USER-20170626GN> Set-AzureWebsite -Name $wsName -ConnectionStrings $connStrs

4 Configure a custom domain

XX.azurewebsite.net(default)->XX.com.
Attention:Custom DNS is not supported in the Free tier. +

步骤:
1、在域名注册商(domain registar)处获取域名
2、在域名注册商(domain registar)处 为域名添加 DNS 记录
3、将特定域名与Azure 网站相关联

Add DNS records

1、A record
A (Address) 记录是用来指定主机名(或域名)对应的IP地址记录。用户可以将该域名下的网站服务器指向到自己的web server上。同时也可以设置您域名的二级域名。在Azure website中, IP不是某个VM的IP,而是网站运行的服务器集群的IP。
如何获取IP:Custom Domain->External IP address
To map an A record to an app, App Service requires two DNS records:

Type Name Value
A xx.com IP addr: 10.200.XX.XX
TXT xx.com <app_name>.azurewebsites.net

TXT: 记录,一般指为某个主机名或域名设置的说

2、CANME record
CANME : 别名记录。这种记录允许您将多个名字映射到另外一个域名
Add a CNAME record to map a subdomain to the app's default hostname <app_name>.azurewebsites.net

Associate the custom domain

  1. Set-AzureWebsite -Name $wsName -HostName @(www.XX.com,"XX.com")

5 Configure SSL Certificate

Must be Standard. Custom SSL is not supported in the Free or Shared tier

wildcard certificate :

通配型证书(wildcard certificate)是在一个域及其所有子域上应用的数字证书。

步骤:
1、获得SSL证书
2、上传证书到Azure
3、绑定

obtain an SSL certificate

SSL证书需要满足以下要求:
1、有私钥
2、可被转换为 .pfx格式(Personal Information Exchange)
3、证书的主体名字与custom域名一致。多个custom 域名,则需要共享证书,使用 wildcard certificate or subject alternative name
4、需要使用 2048-bit以上加密

upload and bind

Portal:
SSL Certificates
->Import or Upload
->Binding
Server Name Indication (SNI) or IP based SSL

1、如果使用IP based SSL,custom IP 使用A record 配置,Azure会为你的网站分配新的IP地址,因此需要在域名注册商处更新A record 的IP
2、基于 SNI 的 SSL 适用于新式浏览器,而基于 IP 的 SSL 适用于所有浏览器。

6 Configure Azure Traffic Manager

Azure Traffic Manager

Network service that route user to websites deployment in potentially different DCs in the world

步骤:
1、创建 Azure Traffic Manager Profile
2、添加 endpoint 到 profile
3、更新 custom domian的 DNS record

Create an Azure Traffic Manager profile

All ATM profile use shared domian *.trafficmanager.net->yourdomianname.trafficmanager.net

DNS Time-to-live (TTL), tells DNS clients how long to cache the name resolved by ATM.

Create a Traffic Manager profile to define the routing method used to distribute user traffic to service endpoints in different datacenters. Traffic Manager endpoints can be Azure virtual machines, web apps, cloud services, and external non-Azure endpoints.
Distribute traffic to your endpoints:
排序方式

https://docs.microsoft.com/en-us/azure/traffic-manager/traffic-manager-routing-methods

portal:
New > Networking > See all, click Traffic Manager profile to open the Create Traffic Manager profile blade, then click Create.

PS:

  1. New-AzureTrafficManagerProfile -Name $wsName `
  2. -DomianName yy-test-web.trafficmanager.net -RoutingMethod Geographic

Add endpoint to ATM

Must be Standard mode

Portal:
1、In the Traffic Manager profile blade, in the Settings section, click Endpoints.
2、In the Endpoints blade that is displayed, click Add

PS:

  1. $tmProfile=Get-AzureTrafficManagerProfile -Name $wsName
  2. Add-AzureTrafficManagerEndpoint -TrafficManagerProfile $tmProfile `
  3. -DomianName "yy-test-web.trafficmanager.net" `
  4. -Type "Azure endpoint" -Name yy-test - Target resource "" -Priority 1 | `
  5. Set-AzureTrafficManagerProfile

Updating DNS Records for custom domain

update custom domain to point to ATM DNS using CNAME

Type Name Value
CNAME youdomairname.com youdomainname.trafficmanager.net

7 Configure Handler Mapping

处理器映射(handler mapping)

HandlerMapping是把一个URL指定到一个Controller.通过处理器映射,你可以将web请求映射到正确的处理器(handler)上。

Portal:
> Appication Settings

PS:

  1. $HandlerMapping = New-Object Microsoft.WindowsAzure.Commands.Utilities.Websites.Services.WebEntities.HandlerMapping
  2. $HandlerMapping.Extension = "*.php"
  3. $HandlerMapping.ScriptProcessor="d:\\\"
  4. Set-AzureWebsite -Name $wsName -HandlerMappings $handlerMapping

8 Configure virtual app and directories

Portal:
> Appication Settings
vitual directory
pyhsical directory

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注