spring-boot - Spring Boot 执行器页面返回 http 链接而不是 https

标签 spring-boot

我有一个 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 重定向到另一个运行 Spring Boot 并嵌入 Tomcat 的 Pod,并使用 HTTP 和端口 8080 提供其内容。

对于 Nginx,有一个代理传递配置:

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

正在添加以下 header :

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

...以便 Spring Boot 知道“原始”请求。

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

最佳答案

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

@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 header 。尽管目前还不清楚为什么执行器实现默认情况下不执行此操作(因为其他 X-Forwarded header 已得到正确处理)

关于spring-boot - Spring Boot 执行器页面返回 http 链接而不是 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52077013/

相关文章:

java - 运行 Jar 时强制启用 spring-boot DevTools

java - Spring Boot-如何在Process Builder中指定Java路径

mysql - 更改 spring jpa 现有表列类型

spring-boot - 可执行Spring Boot 2 jar

java - kafka消费者组线程的线程顺序在每次启动时都不同

java - 如何以 Thymeleaf 形式显示嵌套对象值

java - Spring-boot内部jar文件加载顺序? (嵌入式tomcat)

Maven 依赖项上的 java.lang.ClassNotFoundException

java - 发布请求因无效文件路径错误而失败

java - 如何解决Spring boot @EnableAsync和@Async问题?