您的位置 首页 java

java项目https升级实战

一个很老的项目需要在生产中使用https,记录下!

目标使用http访问网站自动跳转到https,代码中不强制使用https以便可以在开发测试环境方便使用。

关键字 java ,springmvc,shiro, tomcat , nginx .

1,项目部署图

升级后部署图

2,需要的改动:

  1. nginx :

80端口 server 中 增加

rewrite ^(.*)$ 
 

修改目的:使浏览器从http 跳转到https,使用301跳转可以让浏览器缓存,减少网络连接次数。

配置中增加

proxy_set_header X-Forwarded-Proto $scheme;
 

修改目的:shiro,Spring Security等使用 servlet Request#isSecure() 方法判断是否是 SSL 环境,增加这个配置可以使登录跳转到https。

  • java 项目 spring 配置文件
< bean  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!--新增加-->
<property name="redirectHttp10Compatible" value="false" />
</bean>
 

这里使用的是 jsp ,如果是其他视图解析器 也需要做相应配置。

修改目的使spring redirect 能跳转到https 而不是http。

  • tomcat

增加配置

<Valve className="org. apache .catalina.valves.RemoteIpValve"
 remoteIpHeader="x-forwarded-for"
 proxiesHeader="x-forwarded-by"
 protocolHeader="x-forwarded-proto" />
 

end!

文章来源:智云一二三科技

文章标题:java项目https升级实战

文章地址:https://www.zhihuclub.com/178510.shtml

关于作者: 智云科技

热门文章

网站地图