无法使用webconfig中的applicationInitialization来预热页面 [英] Cannot warm up pages using applicationInitialization in webconfig

查看:639
本文介绍了无法使用webconfig中的applicationInitialization来预热页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Umbraco 7.7.2应用程序,并将其托管在Azure(应用程序服务)上。当我重新启动服务器时,第一次请求一个页面需要20-40秒,这在负载很高并且您向外扩展以减少响应时间时特别令人讨厌。

I have a simple Umbraco 7.7.2 application and I'm hosting it on Azure (app-service). When I restart the server it takes 20-40 seconds for first time requesting a page which is really annoying specially when the load is high and you are Scaling out to reduce the response times.

我已经在webconnfig中尝试了此设置,但它似乎不起作用。

I've tried this setting in my webconnfig, but it doesn't seem to work.

<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分钟而不请求任何页面。

I might be trying it in a wrong way, but what I did was to restart the server and I've left it for 2-3 minutes without requesting any page.

我已经检查了Umbraco日志,但该应用程序甚至还没有启动。
然后我请求主页,它花了40秒钟。

I've checked my Umbraco logs and the application wasn't even started. Then I've requested the home page and it took 40 seconds to come up.

然后我尝试了mydomain.com/page1,它也花了自从它是第一个请求访问它以来的20秒。

Then I've tried mydomain.com/page1 and it also took 20 seconds since it was the first request to access it.

* PS:第一个请求之后,该站点非常快,每个页面的加载时间不到100毫秒

*P.S: after the first request, the site is very fast and each page takes less than 100 ms to load

我已按照Kevin的建议进行了重写,以阻止下一次重定向。
结果,我的Umbraco将启动,但请求仍未到达页面。

I've implemented a rewrite to stop next redirects as Kevin has suggested. As a result, my Umbraco will start up, but still the requests doesn't reach to the pages.

在我的母版页上,我添加了如果在查询字符串中有预热并且在页面被浏览器击中的情况下可以在日志中写一行,则该行将起作用:

On my master page, I've added a line to write a line in the logs if it has the warmup in the querystring and it works it the page is hitted from the browser:

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]信息Umbraco.Core.CoreBootManager-Umbraco应用程序启动完成(耗时12727ms)
2018-02-08 15:16:54,911 [P7036 / D2 / T1]信息MyNamespace.Web.CustomStartup-基本配置已完成!

2018-02-08 15:16:51,245 [P7036/D2/T1] INFO Umbraco.Core.CoreBootManager - Umbraco application startup complete (took 12727ms) 2018-02-08 15:16:54,911 [P7036/D2/T1] INFO MyNamespace.Web.CustomStartup - base config done!

这是我根据Kevin的回答添加的confing:

Here is the confing that I've added based on Kevin's answer:

 <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>

此外,我在Microsoft上找到了另一个类似的配置:

Also, I've found another similar config on Microsoft:

   <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>


推荐答案

请求无法到达我的原因很多该网站,并感谢 Kevin Twamley ,他们睁开了我的眼睛,我找到了所有可能的原因。

There was so many reasons for the requests not reaching my site and thanks to Kevin and Twamley whom opened my eyes to the probable cause I could trace and find all of them.

首先,正如凯文所说,HTTPS是我已解决的问题之一,

First, as Kevin said HTTPS was one of the issues which I've fixed as below:

 <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启动了,但请求没有到达我的页面。

Then I could see that Umbraco starts up but the requests didn't get to my pages.

  <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 />

I didn't expect my requests to get to this redirect since it was at the end of my rewrite rules and therefore it should be stoped at No redirect on warmup request but it didn't so I've added another condition to it: <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 ...,初始化将根本无法访问我的网站。

Also, I have ipSecurity in my settings since it is my test environment and I didn't want it open to public. Turns out the Initialization cannot hit my site at all if I don't open up to 127.0.0.1.....

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

这篇关于无法使用webconfig中的applicationInitialization来预热页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆