【问题标题】:Spring Boot actuator page returning http links instead of httpsSpring Boot 执行器页面返回 http 链接而不是 https
【发布时间】:2019-02-04 05:12:54
【问题描述】:

我有一个 Spring Boot 2.0.2 应用程序。当我浏览到以下 URL:https://my-domain-name/my-application-name/actuator,我得到以下输出:

{
    "_links": {
        "self": {
            "href": "http://my-domain-name/my-application-name/actuator",
            "templated": false
        },
        "health": {
            "href": "http://my-domain-name/my-application-name/actuator/health",
            "templated": false
        },
        "info": {
            "href": "http://my-domain-name/my-application-name/actuator/info",
            "templated": false
        }
    }
}

如您所见,内容还可以,但所有链接都以“http”开头,而不是以 https 开头。不过,我正在使用 HTTPS 访问 URL。

我尝试访问的域名是 AWS Route 53 记录,具有 AWS ELB 的别名。此 ELB 将调用重定向到一个目标,即 K8S 集群。 pod 本身正在运行 Nginx,它将 URL 重定向到另一个 pod,该 pod 运行带有嵌入式 Tomcat 的 Spring Boot,并使用 HTTP 和端口 8080 提供其内容。

对于 Nginx,有一个代理通道配置:

location /my-application-name { proxy_pass http://my-application-name; }

正在添加以下标题:

proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;

... 这样 Spring Boot 就会知道“原始”请求。

有人知道我做错了什么吗?执行器实现似乎没有考虑 HTTPS 协议

【问题讨论】:

    标签: spring-boot


    【解决方案1】:

    我通过在配置类中添加这个代码块解决了这个问题:

    @Bean
    public FilterRegistrationBean forwardedHeaderFilterRegistration() {
        ForwardedHeaderFilter filter = new ForwardedHeaderFilter();
        FilterRegistrationBean<ForwardedHeaderFilter> registration = new FilterRegistrationBean<>(filter);
        registration.setName("forwardedHeaderFilter");
        registration.setOrder(10000);
        return registration;
    }
    

    似乎ForwardedHeaderFilter确实考虑了X-Forwarded-Proto 标头。虽然目前还不清楚为什么执行器实现默认不这样做(因为其他 X-Forwarded 标头正在被正确处理)

    【讨论】:

      猜你喜欢
      • 2017-04-12
      • 2018-07-27
      • 2018-05-07
      • 1970-01-01
      • 2016-10-17
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多