解决Nginx+Tomcat下客户端https请求跳转成http的问题
Nginx上開啟https, ?后端使用Tomcat, ?兩者間走http協議, 但發現如果tomcat應用存在跳轉時, 則客戶端瀏覽器會出現400 Bad Request的錯誤, 通過抓包發現原因是302跳轉響應的Location頭中的URL是http協議的, ?在tomcat的端號采用非標準80端口時會導致客戶端出現400. ?解決方案是修改nginx.conf, 讓nginx將302跳轉響應能智能的修改location頭域的內容, ?即添加以下一行到配置中的server段
?
問題:瀏覽器打開https://www.ttlsa.com/aaa.html,然后跳轉到http://www.ttlsa.com/aaa.html
網站架構:用戶--https--->nginx代理---http---->tomcat/nginx+php
nginx待遇發給后端的請求是http協議,后端程序跳轉獲取到的協議是http,返回一個redirect(http header中帶Location:http://www.ttlsa.com/aaa.html),瀏覽器收到location,跳轉到了location指定的地方。
?
proxy_redirect http:// $scheme://;
?
nginx代理中配置proxy_redirect
proxy_redirect http:// $scheme://;
以上指令會將后端響應header location內容中的http://替換成用戶端協議https://。
NGINX訪問https跳轉到http的解決了~
?
?例如:
?
server
{
listen 8443;
server_name test.com;
access_log logs/test.com.access.log main;
?
?
ssl on;
ssl_certificate /home/test/cer/server.crt;
ssl_certificate_key /home/test/cer/server.key;
?
?
ssl_session_timeout 5m;
?
?
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
?
location /projectname?{
proxy_pass http://192.168.1.33:8080;
proxy_set_header Host $host:$server_port;
proxy_redirect http:// $scheme://;
}
轉載于:https://www.cnblogs.com/charon2/p/10349754.html
總結
以上是生活随笔為你收集整理的解决Nginx+Tomcat下客户端https请求跳转成http的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode-95-Unique B
- 下一篇: Nginx —— 检查配置文件ngi