2016-06-16 99 views
1

我使用春天開機:1.3.3彈簧HATEOAS:0.19.0彈簧數據休息核心:2.4.4強制春天HATEOAS產生HTTPS鏈接,而不是HTTP

{ 
    "_embedded" : { 
    "projects" : [ { 
     "status" : "ACTIVE", 
     "storageRegion" : "US", 
     "dataSize" : 96850, 
     "freemiumUnits" : 1, 
     "_links" : { 
     "self" : { 
      "href" : "http://example.com/x-region-us/api/data/projects/2c9f93b755359a4a015535c19b1f0006" 
     }, 
     "project" : { 
      "href" : "http://example.com/x-region-us/api/data/projects/2c9f93b755359a4a015535c19b1f0006" 
     }, 

這是spring-hateoas提供的內容的例子。一段時間後,我將我的應用程序切換到SSL。到跳(跳)通過 「_links」 使用traverson.js時

問題就來了。錯誤occures:

traverson.min.js:2混合內容:該頁面在 'https://example.com/project-new' 裝載了HTTPS,但要求 一個不安全的XMLHttpRequest端點 'http://example.com/x-region-us/api/data/submittalActions'。此 請求已被阻止;內容必須通過HTTPS提供。

有沒有辦法迫使彈簧產生HTTPS鏈接在HTTP「_links」 JSON的一部分?

+0

當你調用REST端點通過自動發生'https'。 – zeroflagL

+0

@zeroflagL它不會發生。我通過'https'調用端點,但_ _ _ links _屬性中的_href_都帶有'http'前綴... –

+0

在應用程序前面是否有代理服務器或Web服務器? – zeroflagL

回答

0

下面的標題添加到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; 
0

如果您使用Apache HTTP服務器,你需要在配置文件中加入這一行:

RequestHeader set X-Forwarded-Proto "https"