1

我遇到了与此问题中所述相同的问题:如何不在 nginx 访问日志中记录获取请求参数?

但是,由于 nginx 是通过 AWS 配置的,所以我在部署时不确定如何修改它。我不清楚这些配置的去向。AWS 支持无法提供帮助,因为这是 nginx 而不是 AWS 的问题。

任何可以为我指明正确方向的信息将不胜感激。

到目前为止,我所拥有的只是我可以./ebextensions/nginx.config在部署到 EB 的存储库中进行修改,但其中需要设置的内容尚不清楚。

==================================

好的,所以一些有趣的更新。基本上,AWS EB 环境为其实例设置了默认的 nginx.configs。在这些配置中,它包括某个路径中的所有 *.config 文件,包括一个包含服务器指令的自动生成文件。它将所有这些注入到 nginx.config 的 http 指令中。

确实可以选择完全覆盖 nginx 配置。但是,作为一个对那里发生的一切以及这样做的潜在危险几乎一无所知的人,我认为最好不要尽可能地修改默认行为。因此,我决定找到一种方法来修改这个自动生成的 .config 文件并重新启动 nginx。

到目前为止,我所拥有的是我的./ebextensions/01_proxy.config

files:
  "/etc/nginx/conf.d/injectObfuscation.sh":
    content: |
      # This script expects a file as input with an nginx server directive to be injected into the http directive of an nginx.config file.
      # It will make two modifications:
      # - It will create a log_format to be used when filtering the password parameter
      # - It will find the server directive and inject a location directive for the sensitive endpoint
      #   - This directive will replace the sensitive parameter with *s and use the filter log_format instead of the main log_format
      # TODO: Figure out how to do the above ^^

container_commands:
  01_update_server_directive:
    command: "./etc/nginx/conf.d/injectObfuscation.sh /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf"
  02_reload_nginx:
    command: "sudo service nginx reload"

files:行声明我正在创建一些文件以添加到 EC2 实例。在这里,我的目标是创建一个 bash 脚本来完成我的任务。如评论中所述,我的任务是首先使用 log_format 添加一行。然后,找到带有 的行server{,在它下面我需要locations /my/sensitive/endpoint完整地注入指令。

对于编写这个我完全不熟悉的 bash 脚本的任何帮助,将不胜感激。

4

1 回答 1

1

我的尝试很愚蠢。

我需要覆盖默认的 nginx.conf 和 00_elastic_beanstalk_proxy.conf 就像在 Node.js 特定文档中一样:https ://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-proxy.html

EB上的其他平台允许你添加a.ebextensions/nginx/nginx.conf覆盖现有的nginx.conf,但是Node的启动过程好像不一样,忽略了这个文件。但是,您可以使用 .ebextension 配置创建一个文件/etc/nginx/nginx.conf来替换它。

出于我的目的,我这样做并更改$request$temp主要 log_format。

对于 Node 环境,服务器指令存在于00_elastic_beanstalk_proxy.conf实例在启动期间自动生成的文件中。使用上面文档中的示例,我覆盖了它并添加了逻辑来混淆我需要的参数。可选地,这可以放置在此覆盖文件内的位置指令中。我可以定义一个单独的日志格式。但出于我的目的,我希望无论路径如何都不会记录此参数。

AWS 指出,默认的 nginx.conf 和 00_elastic_beanstalk_proxy.conf 可能会根据您使用的节点环境的版本而改变,因此请始终从特定版本中提取一个。

我所做的一种尝试是只覆盖 nginx.conf。但是,set 指令只能在 location、server 和另一个我不记得的指令中使用。在 http 指令本身内设置变量是无效的。

于 2018-08-17T03:42:27.753 回答