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



beanstall文档不清楚在部署PHP应用程序时如何以及什么是自定义nginx配置的最佳方式。

我尝试了很多东西,包括一个文件/etc/nginx/conf.d/01security.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;

我试过其他选择,但似乎都不起作用。我有点困惑,因为豆茎没有给出任何明确的方向,应该如何为PHP做到这一点?我见过人们使用不同的策略,其中一些早在2018年、2017年…

我可以使用container_commands替换配置,然后重新启动nginx,但有什么方法可以添加更多的配置文件或修改原始配置文件?

您的/etc/nginx/conf.d/01-security.conf不工作的一个可能原因是您正在使用AmazonLinux2(AL2(。但是,该设置文件适用于基于AL1的旧EB平台。

对于AL2,nginx设置应该在.platform/nginx/conf.d/中,而不是在文档中所示的.ebextentions中。

因此,您可以拥有以下内容的.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;

以上是示例。我无法验证这些设置是否真的有效,但在我看来,你使用的是AL2,而不是AL1。在这种情况下,nginx配置文件使用了错误的文件夹。

最新更新