【问题标题】:How to change AWS Elastic Beanstalk to forward original ip address of request?如何更改 AWS Elastic Beanstalk 以转发请求的原始 IP 地址?
【发布时间】:2017-02-16 02:56:58
【问题描述】:

我对所有这些服务器/ngInx 的东西都很陌生,所以我在转发请求的正确 IP 地址时遇到了问题。截至目前,所有请求都来自 IP 地址 127.0.0.1(在 AWS 内部)。但是,我需要能够验证请求的原始 IP 地址是什么。

正如我读过here,我需要在ngInx 中指定以下选项:

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

但是,我没有在 AWS 上使用 nginx 的自定义配置。有没有办法只将这两行添加到 aws 上 nginx 的默认配置中?

【问题讨论】:

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


    【解决方案1】:

    我不是 nginx 专家,但你可以使用 ebextensions (http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html) 来解决这个问题。

    基本上你首先需要把这个新配置放在一个 nginx 配置文件中,如下所示:

        files:
          "/etc/nginx/conf.d/proxy.conf" :
            mode: "000755"
            owner: root
            group: root
            content: |
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    

    然后你还需要使用 container_commands 重新加载 nginx,如下所示:

    container_commands:
      01_reload_nginx:
        command: "service nginx reload"
    

    希望对你有帮助!

    【讨论】:

    • 我应该使用ebextensions下的environment.config文件中的所有这些吗?
    猜你喜欢
    • 2023-03-03
    • 2018-07-04
    • 1970-01-01
    • 2021-08-06
    • 2019-05-02
    • 2020-10-06
    • 2015-06-21
    • 1970-01-01
    • 2014-07-03
    相关资源
    最近更新 更多