【问题标题】:Nginx reverse proxy for AWS APIGatewayAWS APIGateway 的 Nginx 反向代理
【发布时间】:2020-02-15 05:42:32
【问题描述】:

我的用例是我想路由以下请求 http://localhost/STAGE/RESOURCE/123https://MyGatewayID.execute-api.us-west-2.amazonaws.com/STAGE/RESOURCE/123

其中 123 是路径参数

我正在尝试使用 Nginx 为我的 AWS API Gateway 设置反向代理,但在通过邮递员进行测试时出现以下错误

我们计算的请求签名与您提供的签名不匹配。检查您的 AWS 秘密访问密钥和签名方法。有关详细信息,请参阅服务文档。\n\n此请求的规范字符串应该是\n'GET\n/alpha/data/ ...

我已经配置了带有访问密钥和秘密的 AWS 授权标头,以便在使用 API Gateway url 时使用邮递员成功访问 API Gateway,但是当我用 localhost 替换它时,它给出了上述错误

这在邮递员中工作 https://MyGatewayID.execute-api.us-west-2.amazonaws.com/STAGE/RESOURCE/123

这在邮递员中不起作用 https://localhost/STAGE/RESOURCE/123

这是我的 nginx 配置

   server {

    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  localhost;
    root         /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
            proxy_set_header Host $proxy_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass https://MyGatewayID.execute-api.us-west-2.amazonaws.com;
            proxy_ssl_server_name on;
            proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            proxy_buffering off;
    }

【问题讨论】:

    标签: nginx aws-api-gateway nginx-reverse-proxy nginx-config


    【解决方案1】:

    签名不匹配,因为主机名用于生成签名。 Postman 使用“localhost”生成签名,API Gateway 期待“MyGatewayID.execute-api.us-west-2.amazonaws.com”。

    有关签名组件的完整详细信息,请参阅Authenticating Requests (AWS Signature Version 4)

    作为一种解决方法,将您的网关主机名作为 Host 标头添加到您的请求中。 Postman 将在生成签名时使用它。

    我遇到了同样的问题。除了我不希望我的用户必须知道我的私有网关的主机名。

    【讨论】:

      猜你喜欢
      • 2021-05-26
      • 2019-07-30
      • 2020-11-02
      • 1970-01-01
      • 1970-01-01
      • 2018-05-10
      • 2020-01-05
      • 2017-05-28
      • 2021-09-05
      相关资源
      最近更新 更多