2013-03-12 74 views
0

我試圖用Nginx和Tomcat做ssh卸載。我的設置是: 瀏覽器 - (HTTPS) - > nginx - >(http/https) - > tomcat

我已經設置nginx轉發請求方案在x -forward-proto頭。

    proxy_pass http://default_upstream; 
        add_header Set-Cookie "SRVGROUP=$group; path=/"; 
        proxy_next_upstream error; 
        proxy_set_header Host $host; 
        proxy_set_header X-Real-IP $remote_addr; 
        proxy_set_header X-Host $http_host; 
        proxy_set_header X-Forwarded-For $http_x_forwarded_for; 
        proxy_set_header X-URI $uri; 
        proxy_set_header X-ARGS $args; 
        proxy_set_header X-Forwarded-Proto $scheme; 
        proxy_set_header X-Scheme $scheme; 
        proxy_set_header Refer $http_refer; 
        proxy_redirect http:// $scheme://; 
        proxy_set_header Strict-Transport-Security "max-age=7200"; 

在tomcat上打印X-Forwarded-Proto頭文件我總是得到http。 如果我更換

proxy_set_header X-Forwarded-Proto $scheme; 

proxy_set_header X-Forwarded-Proto https; 

它所有的作品。但我想使用$ scheme,因爲並非所有頁面都通過https提供。

正在尋找解決方案,或者之前是否有人遇到過相同的問題。

回答

1

我找到了。在我的nginx的配置SSL有人已經離開了這一點:

proxy_pass http://127.0.0.1; 

這幾乎重定向再次nginx的,但80端口上。我評論它,現在這一切工作正常。

感謝大家的幫助。

0

proxy_set_header X-Forwarded-Proto https;對於SSL卸載是正確的。你似乎期待的是Nginx代理http連接。這也是可行的,但您需要分別將其設置爲端口80的偵聽器,然後將代理連接設置爲上游服務器。

基本上,你需要443端口和80端口

0

進行一些小改動試過你的配置在我的devbox單獨的服務器配置塊。我的上游腳本在從https訪問時會看到「https」,當它來自http時會看到「http」。所以你的配置工作。

我改變的唯一的一行是發送到上游的主機頭。從

proxy_set_header Host $host; 

proxy_set_header Host my_upstream_domain_name; 

我有兩個位點(上游/下游)託管在同一devbox。所以如果主機頭指向當前的域名,而不是上游的域名,我的測試將不起作用。

如果您的上游託管在另一臺服務器上,則上述更改可能與您的測試無關。

2

請嘗試:

方法一:

proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; 

方法2:

nginx.conf 
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; 

server.xml: 

<Valve className="org.apache.catalina.valves.RemoteIpValve" 
     remoteIpHeader="x-forwarded-for" 
     remoteIpProxiesHeader="x-forwarded-by" 
     protocolHeader="X-Forwarded-Proto" 
     httpsServerPort="443" 
    /> 

如果你仍然有問題,我建議你和tcpdump nginx的和Tomcat

之間的數據