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://;

    }

  • 相关阅读:
    ubuntu 16.0.5 修改网卡为固定IP
    Ubuntu PostgreSQL安装和配置
    NPOI 1.2.1版本替换为2.4.0版本实体类变更
    C# 之 Math取整
    解决github 下载过慢的问题
    优伦自动语言话务员设置
    python3学习笔记 列表
    【postgresql】role "root" does not exist 解决办法
    Eclipse使用的小技巧
    Servlet
  • 原文地址:https://www.cnblogs.com/charon2/p/10349754.html
Copyright © 2011-2022 走看看