【问题标题】:Enabling gzip compression on Azure App Service for Containers在 Azure App Service for Containers 上启用 gzip 压缩
【发布时间】:2020-08-24 13:51:19
【问题描述】:

我刚刚在一个使用 Docker 容器托管在 Azure 服务 Linux 上的网站上进行了 Google PageSpeed Insights 测试。

结果不好,主要抱怨的是没有一个请求被gzip。

我搜索了一下,没有找到有关如何为容器服务启用此功能的详细信息。诸如此类的答案仅适用于带有 web.config 的常规网站,而我没有。 Enabling gzip compression on Azure App Service

我发现我可以在 asp net core 中启用此功能(我在容器中托管的内容)using this. 但我更喜欢托管服务器这样做,因为我确信这会更好。这也是该页面上文档所说的内容。

在 IIS、Apache 或 Nginx。中间件的性能可能无法与 服务器模块。

那么,如何使用在 Linux 上运行的容器在应用服务中启用 Gzip 压缩?

【问题讨论】:

    标签: azure azure-container-service azure-appservice


    【解决方案1】:

    我最终这样做了。我认为没有办法使用容器在应用服务中启用压缩。

    这总比没有好。

    public class Startup
    {
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddResponseCompression();
        }
    
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseResponseCompression();
        }
    }
    

    【讨论】:

      【解决方案2】:

      您是否使用任何网络服务器来处理请求(例如 IISC、apache 等)?如果是这样,更好的方法是在 Web 服务器中启用 gzip 压缩,而不是在应用服务器中启用压缩。警告也只是暗示。

      【讨论】:

      • "Azure App Service for Containers" 我无法控制任何 IIS 或 Apache 服务器。
      • 你能检查问题的答案 - docs.microsoft.com/en-us/azure/app-service/… 吗?请忽略该问题,但请查看 web.config 设置如何从 azure 门户公开。如果您能够看到它,这可能是设置的公开方式(对于网络服务器)。
      猜你喜欢
      • 2015-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      • 2018-08-20
      • 1970-01-01
      • 2013-05-05
      • 2011-10-11
      相关资源
      最近更新 更多