如何解决NGINX 反向代理重写 SAML 回调
Windows 上的 SonarQube,在 http://localhost/9000 上运行。
我正在设置 NGINX 以用作反向代理并在 https://localip.com 上提供服务。
我在尝试连接到 SonarQube 时收到以下 EE
您无权访问此页面。请联系管理员。原因:响应是在 http://localhost:9000/oauth2/callback/saml 而不是 https://localip.com/oauth2/callback/saml
处收到的我猜我需要指示 NGINX 重写回调,我该怎么做?
解决方法
我有同样的问题,但我运行的是 Apache 服务器,我的代理配置如下:
## Proxy rules
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:9000/
ProxyPassReverse / http://127.0.0.1:9000/
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
添加什么解决问题:
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
,
您没有显示示例配置,但我最近在使用 SAML 的 nginx 反向代理后面设置 SonarQube 9 时遇到了与您相同的问题。
您无权访问此页面。请联系管理员。原因:响应是在 http://localhost:9000/oauth2/callback/saml 而不是 https://localip.com/oauth2/callback/saml
处收到的最可能的解决方法是将这两行添加到您的 nginx 代理配置中的服务器 proxypass 部分:
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Host $host;
Sonarsource 有 a post about this 用于 IIS 反向代理,它们表明 2 件重要的事情:
- HTTP_X_FORWARDED_PROTO 设置为 https
- 保留主机头
我上面的代码片段中的行按顺序处理 #1 和 #2 的 NGINX 等效项。
他们的 Operating the Server 页面也提供了这个示例配置:
# the server directive is Nginx's virtual host directive
server {
# port to listen on. Can also be set to an IP:PORT
listen 443 ssl;
ssl_certificate ${path_to_your_certificate_file}
ssl_certificate_key ${path_to_your_certificate_key_file}
location / {
proxy_pass ${address_of_your_sonarqube_instance_behind_proxy}
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto https;
}
}
根据您的错误消息,proxy_pass 行很可能类似于 proxy_pass http://localhost:9000
。我也是这样设置的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。