强制spring hateoas生成https链接而不是http

强制spring hateoas生成https链接而不是http,https,spring-boot,hateoas,spring-hateoas,Https,Spring Boot,Hateoas,Spring Hateoas,我使用的是SpringBoot:1.3.3、SpringHateOAS:0.19.0和SpringDataRESTCore:2.4.4 这是spring hateoas提供的内容示例。过了一会儿,我将应用程序切换到SSL 使用traverson.js通过“\u链接”跳转(跳跃)时会出现问题。发生错误: traverson.min.js:2混合内容:位于 “”已通过HTTPS加载,但已请求 不安全的XMLHttpRequest端点 ''. 这 请求已被阻止;内容必须通过HTTPS提供 有没有办法强

我使用的是SpringBoot:1.3.3、SpringHateOAS:0.19.0和SpringDataRESTCore:2.4.4

这是spring hateoas提供的内容示例。过了一会儿,我将应用程序切换到SSL

使用traverson.js通过“\u链接”跳转(跳跃)时会出现问题。发生错误:

traverson.min.js:2混合内容:位于 “”已通过HTTPS加载,但已请求 不安全的XMLHttpRequest端点 ''. 这 请求已被阻止;内容必须通过HTTPS提供


有没有办法强制spring在json的“\u links”部分中通过HTTP生成HTTPS链接?

将下面的标题添加到NginX中

proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Prefix $http_x_forwarded_prefix;
proxy_set_header X-Forwarded-Host $http_x_forwarded_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Forwarded-Protocol https;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Url-Scheme https;
proxy_http_version 1.1;

如果使用Apache Http Server,则需要在配置文件中添加以下内容:

RequestHeader set X-Forwarded-Proto "https"

当您通过
https
@zeroplagl调用REST端点时,这会自动发生,但不会发生。我通过
https
调用endpoint,但“\u links”属性中的所有href都带有
http
前缀…应用程序前面是否有代理或web服务器?我猜客户端通过https调用nginx服务器,后者通过http调用Spring Boot。这将导致你描述的结果。还有一个类似的问题,有一位Spring开发人员的评论或回答。可以设置某个标头。@Raca如果您感兴趣:我认为您应该更喜欢标准化版本:
RequestHeader set-Forwarded:proto=https
X-。。。标题在理论上是“实验性的”。不过,这两个版本都在运行。
RequestHeader set X-Forwarded-Proto "https"