Nginx - 轉送 HTTP 驗證 - 用戶

Nginx - 轉送 HTTP 驗證 - 用戶

我在 Nginx 和 Jenkins (Hudson) 方面遇到了一些麻煩。我正在嘗試使用 Nginx 作為具有 HTTP 基本驗證的 Jenkins 實例的反向代理。

到目前為止它有效,但我不知道如何使用身份驗證用戶名傳遞標頭。

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。

相關內容