简体   繁体   English

Elastic Beanstalk - 自定义 Nginx 配置文件 - PHP Web 应用程序

[英]Elastic Beanstalk - Customize Nginx configuration files - PHP Web Application

The beanstalk documentation is not clear on how and what is best way to customize nginx configuration when deploying PHP applications. beanstalk 文档并不清楚在部署 PHP 应用程序时如何以及什么是自定义 nginx 配置的最佳方式。

I've tried multiple things as include a file /etc/nginx/conf.d/01-security.conf like this:我已经尝试了多种方法,包括像这样的文件/etc/nginx/conf.d/01-security.conf

files:
/etc/nginx/conf.d/01-security.conf:
mode: “000644”
owner: root
group: root
content: |
  add_header X-Frame-Options "SAMEORIGIN" always ;
  add_header X-XSS-Protection "1; mode=block" always;
  add_header X-Content-Type-Options "nosniff" always;
  add_header Referrer-Policy "no-referrer-when-downgrade" always;
  add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" 
  always;
  add_header X-Cache-Status $upstream_cache_status;

I've tried other alternatives but none of them seems to be working.我尝试了其他替代方案,但似乎没有一个有效。 I am a bit confused as beanstalk doesn't give any clear direction on how that should be done for PHP?我有点困惑,因为 beanstalk 没有给出任何关于 PHP 应该如何做的明确方向? I've seen people using different strategies, some of them back in 2018, 2017...我见过人们使用不同的策略,其中一些是在 2018 年、2017 年......

I can replace the configuration using container_commands and then restart nginx, but there is any way where I can add more configuration files or modify the original one?我可以使用 container_commands 替换配置,然后重新启动 nginx,但是有什么方法可以添加更多配置文件或修改原始配置文件?

A possible reason why your /etc/nginx/conf.d/01-security.conf is not working, is because you are using Amazon Linux 2 (AL2).您的/etc/nginx/conf.d/01-security.conf一个可能原因是您使用的是Amazon Linux 2 (AL2)。 However, the setting file is for old EB platforms based on AL1.但是,该设置文件适用于基于 AL1 的旧 EB 平台。

For AL2, the nginx settings should be in .platform/nginx/conf.d/ , not in .ebextentions as shown in the docs .对于 AL2,nginx 设置应该在.platform/nginx/conf.d/ ,而不是在.ebextentions ,如文档中所示。

Therefore, you could have the following .platform/nginx/conf.d/myconfig.conf with content:因此,您可以拥有以下.platform/nginx/conf.d/myconfig.conf内容:

add_header X-Frame-Options "SAMEORIGIN" always ;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" 
always;
add_header X-Cache-Status $upstream_cache_status;

The above is an example .以上是一个例子 I can't verify if the settings will actually work, but it seems to me that you are using AL2, not AL1.我无法验证这些设置是否真的有效,但在我看来您使用的是 AL2,而不是 AL1。 In this case, you are ussing wrong folders for the nginx config files.在这种情况下,您为nginx配置文件使用了错误的文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM