nginx https 代理 tomcat http,解决访问https还会跳转http问题

2023-05-16

server {
    listen 443 ssl;
    #配置HTTPS的默认访问端口为443。
    #如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。
    #如果您使用Nginx 1.15.0及以上版本,请使用listen 443 ssl代替listen 443和ssl on。
    server_name www.baidu.com;
    root html;
    index index.html index.htm;
    ssl_certificate cert/9278519_www.baidu.com.pem;
    ssl_certificate_key cert/9278519_www.baidu.com.key;
    ssl_session_timeout 60m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    #表示使用的加密套件的类型。
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; #表示使用的TLS协议的类型,您需要自行评估是否配置TLSv1.1协议。
    ssl_prefer_server_ciphers on;
    location / {
        root /usr/share/nginx/html/;  #Web网站程序存放目录。
        index index.html index.htm;
    }

    location ^~ /h5 {
                proxy_pass http://你的tomcat的ip:端口/h5/;
                proxy_redirect http:// $scheme://;
                proxy_set_header  Host       $host;
                proxy_set_header  X-Real-IP    $remote_addr;
                proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location ^~ /ruoyi {
                proxy_pass http://你的tomcat的ip:端口/ruoyi/;
                proxy_redirect http:// $scheme://;
                proxy_set_header  Host       $host;
                proxy_set_header  X-Real-IP    $remote_addr;
                proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

上述代码中server_name www.baidu.com 要换成你的域名,及ssl_certificate处的证书

其中的如下代码将后端响应header location内容中的http://替换成用户端协议https://

 proxy_redirect http:// $scheme://;

这样tomcat的跳转http请求到达用户前台仍会使用https

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

nginx https 代理 tomcat http,解决访问https还会跳转http问题 的相关文章

随机推荐