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

    }

  • 相关阅读:
    推荐一个wpf&sliverlight的图表控件
    数独求解
    WPF中的 CollectionChanged事件通知
    Windows 7 任务栏之缩略图预览(Thumbnail)
    把Google HK设为IE默认的搜索引擎
    F#小记——1. Hello F#
    F#小记——2. 基本数据类型
    使用异步socket的时候需要注意memory spike
    《everytime you kissed me》的中文歌词
    我回来了o(∩_∩)o...
  • 原文地址:https://www.cnblogs.com/charon2/p/10349754.html
Copyright © 2011-2022 走看看