Ash*_*ous 6 umbraco azure warm-up umbraco7 azure-app-service-envrmnt
我有一个简单的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>
Run Code Online (Sandbox Code Playgroud)
我可能会以错误的方式尝试它,但我做的是重新启动服务器,我已经离开它2-3分钟而没有请求任何页面.
我检查了我的Umbraco日志,应用程序甚至没有启动.然后我已经请求了主页,它花了40秒才出现.
然后我尝试了mydomain.com/page1,它也花了20秒,因为它是第一个访问它的请求.
*PS:第一次请求后,网站速度非常快,每页加载时间不到100毫秒
我已经实现了重写以阻止下一次重定向,正如Kevin建议的那样.结果,我的Umbraco将启动,但请求仍然没有到达页面.
在我的母版页,我添加了一行写在日志中的线路,如果它在查询字符串的热身和它的作品在页面从浏览器hitted:
if (!string.IsNullOrWhiteSpace( Request.QueryString["warmup"]))
{
var pageC = Model.Content;
logger.Info(pageC.UrlAbsolute()+" "+ Request.QueryString);
}
Run Code Online (Sandbox Code Playgroud)
但是,我的日志中没有任何内容
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>
Run Code Online (Sandbox Code Playgroud)
另外,我在微软上发现了另一个类似的配置:
<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>
Run Code Online (Sandbox Code Playgroud)
请注意,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>
Run Code Online (Sandbox Code Playgroud)
请求未到达我的网站的原因有很多,感谢Kevin和Twamley,他们让我看到了可能的原因,我可以追踪并找到所有这些请求。
首先,正如 Kevin 所说,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>
Run Code Online (Sandbox Code Playgroud)
然后我可以看到 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>
Run Code Online (Sandbox Code Playgroud)
我没想到我的请求会到达此重定向,因为它位于我的重写规则的末尾,因此它应该停止在“预热请求上没有重定向”处,但事实并非如此,所以我添加了另一个条件: <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>
Run Code Online (Sandbox Code Playgroud)
另外,我的设置中有 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" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1593 次 |
| 最近记录: |