SonarQube - HAProxy HTTPs 无效 Header

SonarQube - HAProxy HTTPs Invalid Header

我所有的开发系统都支持 haproxy(一切都 dockerized),我可以访问我的 Jenkins / Gitlab / 和 Sonar,但不能访问 Nexus。查看 nexus 容器的 docker 日志后,我可以看到它正在收到请求,但是它说转发 header 无效。我的目标是让 haproxy 使用 https,而 haproxy 背后的应用程序只使用 http。这样应用程序就可以通过代理获得 https,但不需要自己进行配置。

这是日志消息:

nexus_1     | 2018-03-23 17:35:08,874-0500 WARN  [qtp1790585161-43] *SYSTEM 
org.sonatype.nexus.internal.web.HeaderPatternFilter - rejecting request 
from 98.192.146.97 due to invalid header 'X-Forwarded-Proto: \http'

这是我的 nexus haproxy 配置:

frontend www-https
    bind *:443 ssl crt /etc/haproxy/certs/server.pem
    reqadd X-Forwarded-Proto:\http
    acl jenkins hdr_beg(host) -i jenkins.
    acl nexus hdr_beg(host) -i nexus.
    acl git hdr_beg(host) -i git.
    acl sonar hdr_beg(host) -i sonar.

    use_backend jenkins if jenkins
    use_backend nexus if nexus
    use_backend git if git
    use_backend sonar if sonar

backend nexus
    mode http
    balance roundrobin
    option forwardfor
    http-request set-header X-Forwarded-Port %[dst_port]
    server nexus1 nexus:8081 check

我最初有这一行,它存在于我的所有其他应用程序中:

    http-request add-header X-Forwarded-Proto https if { ssl_fc }

但是当启用该功能时,Sonar 会抛出此错误:

nexus_1     | 2018-03-23 23:54:38,132-0500 WARN  [qtp1790585161-43] 
*SYSTEM org.sonatype.nexus.internal.web.HeaderPatternFilter - rejecting 
request from 98.192.146.97 due to invalid header 'X-Forwarded-Proto: 
\http,https'

使用 haproxy 需要什么特殊的 nexus 吗?

编辑:我已经确认如果 "docker-compose exec haproxy sh" 我可以卷曲 "nexus:8081" 并且它给了我 index.html。所以我知道容器可以与nexus容器正确通信。

http-request add-header X-Forwarded-Proto https if { ssl_fc }

在大多数情况下这基本上是错误的。无论您在哪里使用它,您都可能需要更改它,因为您不想 add 这个 header -- 您想要 set它。您需要您的版本来覆盖传入请求中可能包含的任何内容。

http-request set-header X-Forwarded-Proto https if { ssl_fc }

添加 header 会保留以前的值,包括您在这一行中错误添加的值:

reqadd X-Forwarded-Proto:\http

您要么在 \ 之后需要一个 space,要么您需要完全删除 \...但实际上,最好使用 http-request set-header 来完成因为这在操作上优于 req* 操作。

但是无论如何,拥有那条线确实没有明显意义,因为您的前端使用 bind *:443 ssl,所以 ssl_fc 在该前端中始终为真。因此,您的前端只需设置正确的 header.

http-request set-header X-Forwarded-Proto https