Sonarqube位于https代理之后,带有X_转发的_协议

Sonarqube位于https代理之后,带有X_转发的_协议,sonarqube,mod-proxy,sonarqube5.1,Sonarqube,Mod Proxy,Sonarqube5.1,我想要实现的目标: 浏览器->Apache(https)->Sonarqube(http) 问题: 来自声纳的位置标题是http://..,所以 重定向到 我已按照此处所述的标准反向代理基础结构说明进行操作: 想知道我可能遗漏了什么,或者这是否是一个真正的bug 运行参数应为5.1.1 解决方案 @kraal提出的解决方案对我们没有任何影响,但如果您在URI中添加/的话,它就可以工作了 例如 正如我们所看到的,Location仍然设置为http,但是下面的方法可以工作(注意最后的/) 因此,

我想要实现的目标:

浏览器->Apache(https)->Sonarqube(http)

问题:

来自声纳的位置标题是http://..,所以 重定向到

我已按照此处所述的标准反向代理基础结构说明进行操作:

想知道我可能遗漏了什么,或者这是否是一个真正的bug

运行参数应为5.1.1

解决方案

@kraal提出的解决方案对我们没有任何影响,但如果您在URI中添加/的话,它就可以工作了

例如

正如我们所看到的,Location仍然设置为http,但是下面的方法可以工作(注意最后的/)

因此,当Sonar重定向到/Sonar/sessions/new(登录页面)时,似乎发生了一些事情,其行为与/Sonar/to/Sonar不同


将/附加到URI是一种解决方法,对我们来说很有效。

问题可能是由于您的
ProxyPassReverse
。下面是我们的配置摘录(apache<2.2.18):


#指定https和端口是为了确保服务器生成正确的
#自引用URL。
服务器名https://visiblehost:443
# ... 这里有SSL和其他配置
#ProxyRequests必须设置为“off”,因为我们使用Apache作为反向代理。
代理请求关闭
#ProxyPreserveHost必须设置为“开”,以便将主机:行从传入请求传递到
#代理主机,而不是ProxyPass行中指定的主机名。
代理主机
#AllowEncodeDSLASH必须设置为“on”,以保留SonarQube构建的URL,其中包括
#编码斜杠。升级到Apache2.2.18后,需要将属性设置为“NoDecode”。
AllowEncodesOn
#必须设置一些RequestHeaders,以使标头具有https所需的正确值
#通讯。
RequestHeader集合X-Forwarded-Proto“https”
RequestHeader设置X转发端口“443”
#ProxyPass定义Apache使用ajp协议与SonarQube通信
#而且不需要做任何标准化。
#ReverseProxyPass定义https通信仅在客户端之间完成
#还有阿帕奇。
ProxyPass/声纳ajp://hiddenhost:port/sonar 诺卡农
ProxyPassReverse/声纳https://visiblehost/sonar
如您所见,一方面,
ProxyPassReverse
定义了
https
用户与
/sonar
上的反向代理之间必须进行通信。指定的URL是用户“可见”的Apache URL

另一方面,
ProxyPass
定义Apache将
/sonar
上的所有流量发送到一个“隐藏”URL。在我们的例子中,我们使用
AJP
协议以确保此URL不能直接访问,但是如果您使用
http
,则配置应该类似(将
AJP
替换为
http

希望有帮助

Michel

(对于任何偶然发现这篇文章的人,我在谷歌集团发布了一个类似的问题:一位回复者通知我,我无意造成重复)


关于通过更改尾部斜杠对您有效的修复,遗憾的是,这对我不起作用(我已经添加了斜杠),删除它们也不起作用。

在我使用Apache 2.4和Sonarqube 8.0的情况下,我用以下方法解决了问题:

<Location /sonarqube>
        RewriteEngine  On
        RewriteCond %{HTTP:X-Forwarded-Proto} !https
        RewriteCond %{HTTPS} off
        RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

        ProxyPreserveHost On
        ProxyPass http://192.168.10.15:9000/sonarqube
        ProxyPassReverse http://192.168.10.15:9000/sonarqube
</Location>

重新启动发动机
重写cond%{HTTP:X-Forwarded-Proto}!https
重写条件%{HTTPS}关闭
重写规则^https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301,NE]
代理主机
ProxyPasshttp://192.168.10.15:9000/sonarqube
ProxyPassReversehttp://192.168.10.15:9000/sonarqube

感谢您的输入,我已经更新了原始帖子以包含我们的解决方案。您的解决方案不是真正的解决方案,
curl-I
不遵循HTTP 302重定向响应。尝试键入
curl-I-Lhttps://trm.tine.no/sonar
。请注意,您还需要确保正确设置了
sonar.core.serverBaseURL
,即如果要使用https协议,则在SQ设置中设置的服务器基URL必须使用https协议,并且还应使用https协议定义ReverseProxy Pass指令。旁注:为什么在同一主机上将https重定向到http?这意味着任何人都可以通过http URL访问SQ,这意味着你的URL是完全不安全的。也许curl应该遵循重定向,然而,这并没有多大变化,我观察到firefox/chrome中完全相同的行为,即重定向到http。我已经以完全相同的方式配置了4个其他应用程序,它们都在工作,并且没有重定向到http,所以Sonar肯定有不同的功能。Reg侧注:Http将在https确认正常工作后立即关闭!你在设置中正确设置了Sonar的基本URL了吗?谢谢你让我知道,我也会监视google群组的线程
HTTP/1.1 302 Found
Date: Wed, 21 Oct 2015 13:49:39 GMT
Server: Apache-Coyote/1.1
Location: http://trm.tine.no/sonar/
Transfer-Encoding: chunked
curl -I https://trm.tine.no/sonar
HTTP/1.1 302 Found
Date: Thu, 22 Oct 2015 10:53:23 GMT
Server: Apache-Coyote/1.1
Location: http://trm.tine.no/sonar/
Transfer-Encoding: chunked
curl -I https://trm.tine.no/sonar/
HTTP/1.1 302 Found  
Date: Thu, 22 Oct 2015 10:53:25 GMT
Server: Apache-Coyote/1.1
Cache-Control: no-cache
Location: https://trm.tine.no/sonar/sessions/new
X-Frame-Options: SAMEORIGIN
Content-Type: text/html;charset=utf-8
Content-Length: 104
Set-Cookie: JSESSIONID=A8B19F73D93B35BCA24F019EEB848666; Path=/sonar/; HttpOnly
<VirtualHost *:443>
    # https and port are specified in order to make sure that the server generates the correct
    # self-referential URLs.
    ServerName https://visiblehost:443

    # ... SSL and other configuration here

    # ProxyRequests must be set to "off" as we use Apache as a reverse proxy.
    ProxyRequests           Off

    # ProxyPreserveHost must be set to "on" in order to pass the Host: line from the incoming request to the
    # proxied host, instead of the hostname specified in the ProxyPass line.
    ProxyPreserveHost       On

    # AllowEncodedSlashes must be set to "on" in order to preserve urls built by SonarQube which include
    # encoded slashes. Once we upgrade to Apache 2.2.18, the property will need to be set to "NoDecode".
    AllowEncodedSlashes     On

    # Some RequestHeaders must be set in order for the headers to have the right value required for https
    # communications.
    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-Port "443"

    # ProxyPass defines that Apache communicates with SonarQube using ajp protocol
    # and that no canonalization has to be done.
    # ReverseProxyPass defines that https communications are only done between client
    # and Apache.

    ProxyPass               /sonar    ajp://hiddenhost:port/sonar nocanon
    ProxyPassReverse        /sonar    https://visiblehost/sonar

</VirtualHost>
<Location /sonarqube>
        RewriteEngine  On
        RewriteCond %{HTTP:X-Forwarded-Proto} !https
        RewriteCond %{HTTPS} off
        RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

        ProxyPreserveHost On
        ProxyPass http://192.168.10.15:9000/sonarqube
        ProxyPassReverse http://192.168.10.15:9000/sonarqube
</Location>