Nginx - 转发 HTTP 身份验证 - 用户

opH*_*AME 22 ubuntu nginx http-basic-authentication jenkins

我在使用 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;
}
Run Code Online (Sandbox Code Playgroud)

And*_*sov 26

尝试将此指令添加到您的位置块

proxy_set_header Authorization $http_authorization;
proxy_pass_header  Authorization;
Run Code Online (Sandbox Code Playgroud)

  • 这必须是 base64 编码的字符串 http://en.wikipedia.org/wiki/Basic_access_authentication#cite_note-8 尝试解码它 (6认同)
  • ``YXJuZTpraWxsZXI`` 解码为 ``arne:killer`` - 很好的例子@opHASnoNAME :-) (2认同)

Oll*_*lli 8

要使其与 Jenkins 反向代理身份验证插件一起使用:

proxy_set_header Authorization "";
proxy_set_header X-Forwarded-User $remote_user;
Run Code Online (Sandbox Code Playgroud)

如果您不重置Authorization标头,nginx 将默认转发该标头,并且在启用反向代理身份验证插件时,Jenkins (jetty) 将尝试重新对用户进行身份验证,但会失败。

nginx 版本 1.12.1,詹金斯 2.113。