【问题标题】:Elastic Beanstalk - Customize Nginx configuration files - PHP Web ApplicationElastic Beanstalk - 自定义 Nginx 配置文件 - PHP Web 应用程序
【发布时间】:2020-12-15 21:48:05
【问题描述】:

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

我尝试了多种方法,例如包含一个文件 /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;

我尝试了其他替代方法,但似乎都没有奏效。我有点困惑,因为 beanstalk 没有给出任何关于如何为 PHP 完成的明确方向?我见过人们使用不同的策略,其中一些早在 2018 年、2017 年......

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

【问题讨论】:

    标签: php amazon-web-services nginx amazon-elastic-beanstalk


    【解决方案1】:

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

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

    因此,您可以拥有以下 .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 配置文件使用了错误的文件夹。

    【讨论】:

      猜你喜欢
      • 2017-07-24
      • 2015-03-27
      • 2019-01-16
      • 2018-08-27
      • 2015-02-23
      • 2014-01-11
      • 2020-10-30
      • 2019-02-23
      • 2019-09-24
      相关资源
      最近更新 更多