如何在 Amazon Linux 2 平台上使用 Elastic Beanstalk 部署的 Nodejs 中实现 gzip 压缩?

NIT*_*MAR 6 gzip nginx node.js amazon-elastic-beanstalk

根据文档,他们已使用 Amazon Linux 2 平台版本上的配置删除了 Gzip压缩选项。

Sun*_*oon 1

由于所有基于 AL2 的平台都使用 nginx 作为默认反向代理,因此您可以通过覆盖默认的 nginx.conf 或添加其他配置文件来在 nginx 配置中打开 Gzip压缩。

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html#platforms-linux-extend.proxy.nginx

To extend the Elastic Beanstalk default nginx configuration, add .conf configuration files to a folder named .platform/nginx/conf.d/ in your application source bundle. The Elastic Beanstalk nginx configuration includes .conf files in this folder automatically.

~/workspace/my-app/
|-- .platform
|   `-- nginx
|       `-- conf.d
|           `-- myconf.conf
`-- other source files

To override the Elastic Beanstalk default nginx configuration completely, include a configuration in your source bundle at .platform/nginx/nginx.conf:

~/workspace/my-app/
|-- .platform
|   `-- nginx
|       `-- nginx.conf
`-- other source files
Run Code Online (Sandbox Code Playgroud)

在基于 AL2 的 EB 平台的 nginx 默认配置中,nginx.conf 文件中已经有 gzip 压缩选项,即“gzip off;”。如果您选择扩展默认的 nginx 配置,您还需要删除 nginx.conf 文件中的此配置。

应包含在 nginx 配置文件中的 gzip 配置如下所示。

gzip on;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
Run Code Online (Sandbox Code Playgroud)

  • 正如您提到的,如果我选择扩展默认配置,我需要删除 nginx.conf 文件中的此配置。我知道如何扩展但我怎么能删除??? (2认同)