无法使用webconfig

时间:2018-02-05 11:06:36

标签: azure umbraco umbraco7 azure-app-service-envrmnt warm-up

我有一个简单的Umbraco 7.7.2应用程序,我在Azure(app-service)上托管它。当我重新启动服务器时,第一次请求一个非常烦人的页面需要20-40秒,特别是当负载很高并且你缩小以减少响应时间时。

我已经在我的webconnfig中尝试了这个设置,但它似乎无法正常工作。

<system.webServer>
  <applicationInitialization>
    <add initializationPage="/page1/?warmup=1" hostName="mydomain.com" />
    <add initializationPage="/page1/page2/?warmup=1" hostName="mydomain.com" />
  </applicationInitialization>
</system.webServer>

我可能会以错误的方式尝试它,但我所做的是重启服务器并且我已经离开它2-3分钟而没有请求任何页面。

我检查了我的Umbraco日志,应用程序甚至没有启动。 然后我已经请求了主页,它花了40秒才出现。

然后我尝试了mydomain.com/page1,因为它是第一个访问它的请求所花了20秒。

* P.S:第一次请求后,网站速度非常快,每页加载时间不到100毫秒

更新

我已经实施了重写,以阻止凯文建议的下一次重定向。 结果,我的Umbraco将启动,但请求仍然无法到达页面。

在我的母版页面上,如果它在查询字符串中有预热,我在日志中添加了一行来写一行,并且它可以从浏览器访问页面:

if (!string.IsNullOrWhiteSpace( Request.QueryString["warmup"]))
    {
        var pageC = Model.Content;
        logger.Info(pageC.UrlAbsolute()+" "+ Request.QueryString);
    }

但是,

后我的日志中没有任何内容
  

2018-02-08 15:16:51,245 [P7036 / D2 / T1] INFO Umbraco.Core.CoreBootManager - Umbraco应用程序启动完成(耗时12727ms)    2018-02-08 15:16:54,911 [P7036 / D2 / T1] INFO MyNamespace.Web.CustomStartup - 基本配置完成!

以下是我根据Kevin的回答添加的内容:

 <rule name="No redirect on warmup request (request from localhost with warmup user agent)" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{REMOTE_ADDR}" pattern="127.0.0.*" />
              </conditions>
          <action type="Rewrite" url="{URL}" />
        </rule>

另外,我在微软上发现了另一个类似的配置:

   <rule name="No redirect on warmup request (request from localhost with warmup user agent)" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="localhost" />
            <add input="{HTTP_USER_AGENT}" pattern="Initialization" />
          </conditions>
          <action type="Rewrite" url="{URL}" />
        </rule>

3 个答案:

答案 0 :(得分:5)

请注意,azure会对http上的URL进行预热,因此如果您使用重写规则强制使用https,则完整站点不会预热,只有重定向模块才会预热。然后,在azure将其添加到负载均衡器并且第一个https到达umbraco代码之后,它需要完成对Umbraco的预热。我们通过在扩展时检查http日志找到了。

我们无法弄清楚如何使用https告诉azure进行预热,因此我们允许Azure通过制定规则来访问http网站,然后在{REMOTE_ADDR}匹配127.0.0时强制https重写为stopProcessing。*。

    <rule name="Allow localhost to warmup" stopProcessing="true">
      <match url="(.*)"/>
      <conditions>
        <add input="{REMOTE_ADDR}" pattern="127.0.0.*" />
      </conditions>
    </rule>

答案 1 :(得分:3)

请求没有到达我的网站有很多原因,并且感谢 Kevin Twamley ,他们让我看到了我可以追踪到的所有可能的原因它们。

首先,正如凯文所说,HTTPS是我修正过的问题之一:

 <rule name="No redirect on warmup request (request from localhost with warmup user agent)" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="localhost" />
        <add input="{HTTP_USER_AGENT}" pattern="Initialization" />
      </conditions>
      <action type="Rewrite" url="{URL}" />
    </rule>

然后我可以看到Umbraco启动但请求没有到达我的页面。

  <rule name="Redirect rquests to www.example.com" stopProcessing="true" enabled="true">
          <match url="(.*)" />
          <conditions >
            <add input="{HTTP_HOST}" pattern="^example\.com$" />
          </conditions>
          <action type="Redirect" url="https://www.example.com/{R:0}" />
        </rule>

我没想到我的请求会进入此重定向,因为它是在我的重写规则结束时因此应该停在没有重定向请求但是它没有这样做我添加了另一个条件:<add input="{HTTP_USER_AGENT}" pattern="Initialization" negate="true" />

  <rule name="Redirect rquests to www.example.com" stopProcessing="true" enabled="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
            <add input="{HTTP_HOST}" pattern="^example\.com$" />
            <add input="{HTTP_USER_AGENT}" pattern="Initialization" negate="true" />
          </conditions>
          <action type="Redirect" url="https://www.example.com/{R:0}" />
        </rule>

另外,我在我的设置中有ipSecurity,因为它是我的测试环境,我不希望它公开。事实证明,如果我不打开127.0.0.1 .....初始化无法访问我的网站。

 <security>
  <ipSecurity allowUnlisted="false">
    <add ipAddress="127.0.0.1" allowed="true" />
    <add ipAddress="x.x.x.x" allowed="true" />

答案 2 :(得分:2)

我喜欢Kevin的想法,就是将处理停止作为第一个重写规则之一。我注意到他没有采取任何行动,但你加了一个给你。也许试试他的w / o动作?它是文件中的第一条规则吗?

我们使用的另一个选项是将此条件添加到任何问题规则中(注意negate)。

<add input="{REMOTE_ADDR}" pattern="127\.0\.0\.1" negate="true"/>

尝试暂时清除重写规则,直到您确信您的热身工作正常,然后一次添加一些规则以查找并修复问题重定向。强制SSL和尾随斜杠类型规则肯定会导致问题。

此外,hostName可以轻松解决您的麻烦。它应该是您的生产环境的完美匹配。它不使用DNS来解决它,它只是与本地站点对话并将其作为HOST头传递。

我的热身名单中没有任何查询字符串。也许你应该尝试放弃那些。您并不真正需要它们,因为您可以将日志记录代码更改为:

if (Request.IsLocal && Request.UserAgent == "IIS Application Initialization Warmup") {
    // log it
}

记录它们是一个好主意,因为预热请求不会显示在标准IIS日志中。我让我的服务器在热身的开始和结束时通过点击使用该if语句的特殊的第一个和最后一个条目来邮寄给我。来自Azure的一些有用的细节:

new {
    WEBSITE_HOSTNAME = System.Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME"),
    WEBSITE_INSTANCE_ID = System.Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID"),
    WEBSITE_SITE_NAME = System.Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"),
    COMPUTERNAME = System.Environment.GetEnvironmentVariable("COMPUTERNAME"),
    USER_AGENT = Request.UserAgent,
    URL = Request.Url,
    WARM_UP_TIME = (DateTime.UtcNow - _start).ToString()
}