Nginx - HTTP AUTH を転送 - ユーザー

Nginx - HTTP AUTH を転送 - ユーザー

Nginx と Jenkins (Hudson) で問題があります。HTTP 基本認証を使用して、Jenkins インスタンスのリバース プロキシとして Nginx を使用しようとしています。

これまでのところは動作しますが、認証ユーザー名を含むヘッダーを渡す方法がわかりません。

location / {
  auth_basic "Restricted";
  auth_basic_user_file /usr/share/nginx/.htpasswd;
  sendfile off;

  proxy_pass         http://192.168.178.102:8080;
  proxy_redirect     default;
  proxy_set_header   Host             $http_host;
  proxy_set_header   X-Real-IP        $remote_addr;
  proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
  proxy_set_header   X-Forwarded-User $http_authorization; 
  proxy_max_temp_file_size 0;

  #this is the maximum upload size
  client_max_body_size       10m;
  client_body_buffer_size    128k;

  proxy_connect_timeout      90;
  proxy_send_timeout         90;
  proxy_read_timeout         90;             
  proxy_buffer_size          4k;
  proxy_buffers              4 32k;
  proxy_busy_buffers_size    64k;
  proxy_temp_file_write_size 64k;
}

答え1

このディレクティブをロケーションブロックに追加してみてください

proxy_set_header Authorization $http_authorization;
proxy_pass_header  Authorization;

答え2

これを Jenkins リバース プロキシ認証プラグインで動作させるには:

proxy_set_header Authorization "";
proxy_set_header X-Forwarded-User $remote_user;

ヘッダーをリセットしないとAuthorization、nginx はデフォルトでそれを転送し、リバース プロキシ認証プラグインを有効にすると、Jenkins (jetty) はユーザーの再認証を試みますが、失敗します。

nginx バージョン 1.12.1、Jenkins 2.113。

関連情報