nginx proxy_set_body отправляет ноль в обратном прокси - PullRequest
0 голосов
/ 07 марта 2020

Я пытаюсь настроить уровень аутентификации для некоторых приложений, используя модуль auth_request в Nginx.

Мне нужно отправлять собственное тело в службу аутентификации в каждом подзапросе. Моя проблема в том, что вышестоящий сервис получает пустое тело, и я не знаю, почему это происходит.

Я делаю обратный прокси-сервер для приложения Sinatra. Это мой nginx.conf файл:

  server {
    # replace with your domain name
    server_name sinatra-nginx.development;
    # replace this with your static Sinatra app files, root + public
    root /Users/mariogmz/code/sinatra-nginx/public;
    # port to listen for requests on
    listen 80;
    # maximum accepted body size of client request
    client_max_body_size 4G;
    # the server will close connections after this time
    keepalive_timeout 5;

    location / {
      auth_request        /auth;
      auth_request_set    $auth_status $upstream_status;
      try_files $uri @app;
    }

    location @app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      # pass to the upstream unicorn server mentioned above
      proxy_pass http://unicorn_server;
    }

    location = /auth {
      internal;

      proxy_method                    POST;
      proxy_ssl_server_name           on;

      proxy_set_header                Content-Length "";
      proxy_set_header                X-Original-URI $request_uri;
      proxy_set_header                Authorization "bearer SecretForOAuthServer";
      proxy_set_header                Content-Type "application/x-www-form-urlencoded";

      proxy_set_body                  "token=$http_apitoken&token_hint=access_token";
      proxy_pass                      https://kcs5sl2fi9.execute-api.us-east-2.amazonaws.com/dev/okta_auth/health;
     }
  }

Я пробовал proxy_set_body метод, но он не работает, все остальное вроде нормально.

...