zoukankan      html  css  js  c++  java
  • 解决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://;

    }

  • 相关阅读:
    Icinga使用总结
    Linux入门:usermod
    JMeter入门(01)概念和样例
    英语日常词汇:living-room、dining-room vs dining hall
    安装 docker-compose
    CentOS7下安装python-pip
    JMeter入门(03)多台JMeter联合测试
    jmeter入门(02)测试报告各项指标含义
    istio入门(01)istio的优势在哪里?
    Docker学习笔记
  • 原文地址:https://www.cnblogs.com/charon2/p/10349754.html
Copyright © 2011-2022 走看看