Nginx配置Https訪問,tomcat無法正確獲取schema的問題
阿新 • • 發佈:2019-01-10
Nginx配置Https訪問,反向代理tomcat,發現兩個問題:
(1)redirect之後的schema全變成了http。
(2)request.getSchema()全部返回http。
server {
listen 80 default_server;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect http:// $scheme://;
}
}
nginx上配置:
proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme;
tomcat上配置:
<Engine >
<Valve className="org.apache.catalina.valves.RemoteIpValve"
remoteIpHeader="X-Forwarded-For"
protocolHeader="X-Forwarded-Proto"
protocolHeaderHttpsValue="https"/>
</Engine >
重啟,over!
關於 RemoteIpValve,有興趣的同學可以閱讀下 :http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html
Tomcat port of mod_remoteip, this valve replaces the apparent client remote IP address and hostname for the request with the IP address list presented by a proxy or a load balancer via a request headers (e.g. "X-Forwarded-For").
Another feature of this valve is to replace the apparent scheme (http/https) and server port with the scheme presented by a proxy or a load balancer via a request header (e.g. "X-Forwarded-Proto").