公司项目最近须要将http访问改成https,在网上找了些资料配置成功,本身总结下。 web
1、进入jdk安装目录bin文件下,经过keytool工具生成密匙对(标识密匙库)如图1_1: 安全
2、输入命令,生成密匙。如图1_2: dom
keytool -genkey -v -alias weblogicsgepit -keyalg RSA -keysize 512 -keypass sgepit -dname "CN=127.0.0.1,OU=安全实验室,O=安全测试机构,L=北京市,ST=北京,C=CN" -validity 365 -keystore /home/weblogic/weblogic_identity.jks -storepass sgepit ide
3、输入命令,生成证书签发请求*.pem 文件(私有密钥)。如图1_3: 工具
keytool -certreq -v -alias weblogicsgepit -file /home/weblogic/cert_request.pem -keypass sgepit -storepass sgepit -keystore /home/weblogic/weblogic_identity.jks 测试
4、回车后,在/home/weblogic下你会发现生成了两个文件,将生成的 weblogic_identity.jks 和 cert_request.pem 文件拷贝到weblogic 的base_domain 文件夹下,如图1_4: url
5、启动weblogic,进入管理控制台,配置密匙库信息,如图1_5: spa
一、密匙库: 选择 Custom Identity and Custom Trust
二、定制标识密匙库: weblogic_identity.jks
三、定制标识密钥库类型: jks
四、定制标识密钥库密码短语: sgepit
五、确认定制标识密钥库密码短语: sgepit
六、定制信任密钥库: weblogic_identity.jks
七、定制信任密钥库类型: jks
八、定制信任密钥库密码短语: sgepit
九、确认定制信任密钥库密码短语: sgepit code
6、配置SSL信息,如图1_6: xml
选择SSL 选项卡,输入相应的信息。
SSL 选项卡
标识和信任位置: 选择 keystores
私有密钥别名: weblogicsgepit
私有密钥密码短语: sgepit
7、启动SSL监听,如图1_7:
8、OK,配置完毕,输入ip测试啦。
https://127.0.0.1:7002/项目名字 输入这个地址后你会发现https已经能够访问你的项目了。但有个问题是
http://127.0.0.1:7001/项目名字 这个地址同样可以访问项目
这时候要拦截http,使http自动跳转到https。
找到web.xml,加以下代码:
<security-constraint> <web-resource-collection > <web-resource-name >SSL</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint>