在 Azure 应用服务上启用 gzip 压缩 [英] Enabling gzip compression on Azure App Service
问题描述
我有一个托管在 microsoft azure 中的网络应用程序.由于本地 IIS 对静态和动态内容都使用压缩,我希望这也适用于 azure 平台.看起来压缩不起作用,例如 json 和 css 文件未压缩返回:
I have a web app hosted in microsoft azure. As local IIS uses compression for both static and dynamic content I expected this to work on azure platform as well. As it seems compression does not work as json and css files for example are returned uncompressed:
我已尝试设置压缩,如几篇文章中所述(例如 gzip 压缩在 WindowsAzure 网站 或 ) 像这样,结果没有任何变化:
I have tried to set compression as mentioned in serveral posts (e.g. gzip compression in Windows Azure Websites or ) like this without any changes to the result:
<system.webServer>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
<httpCompression>
<dynamicTypes>
<clear />
<add enabled="true" mimeType="text/*"/>
<add enabled="true" mimeType="message/*"/>
<add enabled="true" mimeType="application/x-javascript"/>
<add enabled="true" mimeType="application/javascript"/>
<add enabled="true" mimeType="application/json"/>
<add enabled="false" mimeType="*/*"/>
<add enabled="true" mimeType="application/atom+xml"/>
<add enabled="true" mimeType="application/atom+xml;charset=utf-8"/>
</dynamicTypes>
<staticTypes>
<clear />
<add enabled="true" mimeType="text/*"/>
<add enabled="true" mimeType="message/*"/>
<add enabled="true" mimeType="application/javascript"/>
<add enabled="true" mimeType="application/atom+xml"/>
<add enabled="true" mimeType="application/xaml+xml"/>
<add enabled="true" mimeType="application/json"/>
<add enabled="false" mimeType="*/*"/>
</staticTypes>
</httpCompression>
[...]
</system.webServer>
好像天蓝色的门户网站没有给我任何更改压缩的选项.
As it seems the azure portal does not give me any option to change compression.
我需要做什么才能启用压缩,还是只有在 azure 中使用 Vserver 时才有可能?
What do I need to do to enable compression or is it only possible when using a Vserver in azure?
推荐答案
您可以在 web.config 中更改:
You can change this in the web.config:
<system.webServer>
<urlCompression doStaticCompression="true" doDynamicCompression="true" />
</system.webServer>
然后:
<httpCompression>
<dynamicTypes>
<clear />
<add enabled="true" mimeType="text/*"/>
<add enabled="true" mimeType="message/*"/>
<add enabled="true" mimeType="application/x-javascript"/>
<add enabled="true" mimeType="application/javascript"/>
<add enabled="true" mimeType="application/json"/>
<add enabled="false" mimeType="*/*"/>
<add enabled="true" mimeType="application/atom+xml"/>
<add enabled="true" mimeType="application/atom+xml;charset=utf-8"/>
</dynamicTypes>
<staticTypes>
<clear />
<add enabled="true" mimeType="text/*"/>
<add enabled="true" mimeType="message/*"/>
<add enabled="true" mimeType="application/javascript"/>
<add enabled="true" mimeType="application/atom+xml"/>
<add enabled="true" mimeType="application/xaml+xml"/>
<add enabled="true" mimeType="application/json"/>
<add enabled="false" mimeType="*/*"/>
</staticTypes>
</httpCompression>
来源:微软论坛
这篇关于在 Azure 应用服务上启用 gzip 压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!