解决Nginx https协议代理tomcat服务时Tomcat返回http协议的响应

  • A+

问题描述:

Nginx代理服务器信息
Nginx版本:1.13.7,四层代理,对外端口:443(https代理)

后端Tomcat服务器信息:
Tomcat版本:8.5.39,端口:13080(http协议)

请求与响应过程如下
1.请求域名(非真实场景域名):https://www.zhuimengren.co/
2.浏览器接到请求:http://www.zhuimengren.co/suiji/jg/ (发现跳到了http的请求)

解决办法如下

server {
        listen       443;
        server_name  www.xxx.com;
        access_log  logs/https-www.xxx.com-access.log  main;
        ssl on;
        ssl_certificate   cert/1_xxx_bundle.crt;
        ssl_certificate_key  cert/2_xxx.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        location / {
            proxy_pass        http://172.22.0.17:13080;
        proxy_redirect http:// $scheme://;       #使用proxy_redirect将location中的协议转换为请求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;
        }
    }

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: