首页 > 解决方案 > 上传/部署 zip 文件时,不会创建 .platform 挂钩中的 AWS Elastic Beanstalk 自定义 nginx .conf 文件

问题描述

我正在将 Node JS/Express JS 应用程序部署到 AWS Elastic Beanstalk 环境。我正在创建自定义 nginx 配置文件来更改设置。为此,我创建了以下文件。

{project_root_directory}/.platform/nginx/conf.d/elasticbeanstalk/mynginx.conf

server {
    client_max_body_size 512M;
}

然后像往常一样部署应用程序,我压缩我的项目并将压缩文件上传到 AWS 控制台。更新环境后,我检查了服务器上的文件,它没有。

在此处输入图像描述

为什么该文件不存在,我该如何修复它?

以下是详细信息:

图像是 Amazon Linux 2 AMI。

我在根文件夹中创建了一个 .ebextensions 文件夹,其中包含以下文件:

00-files.config

files:
    "/etc/nginx/conf.d/mynginx.conf" :
        mode: "000755"
        owner: root
        group: root
        content: |
           client_max_body_size 512M;

01-nodecommand.config

option_settings:
  - namespace: aws:elasticbeanstalk:container:nodejs
    option_name: NodeCommand
    value: "npm start"

02-migrationcommand.config

option_settings:
  - namespace: aws:elasticbeanstalk:container:nodejs
    option_name: MigrationCommand
    value: "npx sequelize-cli db:migrate"

然后我再次在根文件夹中创建了 .platform/nginx/conf.d/mynginx.config 文件,其中包含以下内容。

server {
    client_max_body_size 512M;
}

所以我有这样的项目结构。

在此处输入图像描述

然后我压缩项目。然后登录 AWS 控制台并转到 Beanstalk 控制台并在那里上传 zip 文件。

在此处输入图像描述

标签: node.jsamazon-web-servicesexpressnginxamazon-elastic-beanstalk

解决方案


假设您使用的是 Amazon Linux 2 EB 平台,正确的文件夹应该是:

{project_root_directory}/.platform/nginx/conf.d/mynginx.conf

不是

{project_root_directory}/.platform/nginx/conf.d/elasticbeanstalk/mynginx.conf

更新:

mynginx.conf应该是:

client_max_body_size 512M;

推荐阅读