amazon-web-services - AWS Beanstalk 无法在部署时自动创建 nginx 配置文件
问题描述
我创建了一个部署在 AWS Beanstalk Amazon Linux 2 (Python 3.8) 上的 Django API 应用程序。在我的应用程序的一部分中,用户应该能够通过 API 上传文件。
默认情况下,当上传的文件大于 3 MB 并在 Nginx 日志中记录“用户尝试上传大文件”时,Nginx 会向用户返回 CORS 错误。
唯一对我有用的解决方案是创建波纹管配置文件并重新加载 Nginx:
/etc/nginx/conf.d/proxy.conf
:
client_max_body_size 50M;
进而:
sudo service nginx reload
我通过 SSH 连接到我的 beanstalk 应用程序的主机 EC2 手动完成了这个过程。我想在每个部署和每个实例中自动执行此过程。
我在位于我的项目根目录的文件夹中
创建了一个名为nginx_max_upload.config
file 的文件::.ebextensions
nginx_max_upload.config
files:
/etc/nginx/conf.d/proxy.conf:
mode: "000755"
owner: root
group: root
content: |
client_max_body_size 50M
commands:
reload_nginx:
command: "sudo service nginx reload"
ignoreErrors: true
我的问题是,上面的代码没有在指定目录中创建我想要的文件。当我将目录更改为另一个目录/usr/local/bin/proxy.conf
时,文件将成功创建,但无法在 Nginx 配置文件夹中创建配置文件。
我想问题可能出在权限上,但我不知道如何向部署代理授予所需的权限。
另外,我已经尝试了这两种解决方案,但它们都不起作用:
- 我试图在另一个文件夹中创建配置文件,然后通过
mv
命令将其移动到正确的目录,但它没有用。 - Also, I have tried to put the creation code in the predeply hook and put manual
echo
commands in my code. I saw all of myecho
commands output in the beanstalk logs but it didn't do anything (nor creating the file in the nginx configuration neither moving it from somewhere else to the configuration folder).
解决方案
Since you are using Amazon Linux 2 (AL2), your configuration files are incorrect. They used to work in AL1, but for AL2, they are in different place and have different format as shown in the docs.
Thus could have the following .platform/nginx/conf.d/myconfig.conf
(not in .ebextensions
) with content:
client_max_body_size 50M;
推荐阅读
- javascript - Maphilight() 在放大/缩小图像地图后停止正常工作
- php - 将数据从 CSV 插入数据库 codeigniter
- javascript - 用javascript打印页面时显示文本框
- mysql - 总和值的总和值
- java - 如何使用 spring boot 和 aspect 记录请求正文
- php - 如何将 if/else if 转换为循环
- database - 可以拆分数据库中的值和参数吗
- android - 如何从多个活动中调用单个服务?
- facebook - 批准 Facebook 上的应用程序需要多长时间?
- angular - 访问 json 中的数组对象以在 Angular 5 中显示下拉值