我的Spring MVCJava Webjava web 学习

Window下搭建Tomcat +openssl 的Https环

2016-12-30  本文已影响369人  Keike
公司服务转换为Https,外网网站买的证书,正常访问没什么问题,但是自己搭建的局域网访问就需要自己搭建Https环境,其中手机端App只能访问IP地址,所以证书指定的为是IP地址而不是域名,因为正式服务端为Appache+Tomcat +openssl 局域网就直接考虑openssl +tomcat 配置可能有点不一样(PS:keytool 生成证书,我没有尝试过,我嚼着应该差不多,至于为啥纠结Openssl ,满脸泪,我不是做后端的,我说的不算 - -!)
jks证书的生成

set OPENSSL_CONF = openssl.cfg
openssl genrsa - out C:\ca\ca-key.pem 1024
openssl req -new -out C:\ca\ca-req.csr -key C:\ca\ca-key.pem
openssl x509 -req -in c:\ca\ca-req.csr -out c:\ca\ca-cert.pem -signkey c:\ca\ca-key.pem -days 365
keytool -genkey -alias blog_albertsong -validity 365 -keyalg RSA -keysize 1024 -keypass as.1234 -storepass as.1234 -dname "cn=192.168.1.136,ou=department,o=company,l=Beijing,st=Beijing,c=CN" -keystore c:\ca\albertsong.jks -ext san=ip:192.168.1.136,dns:www.baidu.com,dns:www.odincf.com

keytool -certreq -alias blog_albertsong -sigalg MD5withRSA -file c:\ca\albertsong.csr -keypass as.1234 -keystore c:\ca\albertsong.jks -storepass as.1234

openssl x509 -req -in c:\ca\albertsong.csr -out c:\ca\albertsong-cert.pem -CA c:\ca\ca-cert.pem -CAkey c:\ca\ca-key.pem -days 365 -set_serial 1 - extfile C:\OpenSSL-Win64\bin\openssl.cfg -extensions v3_req

keytool -import -v -trustcacerts -storepass changeit -alias root_albertsong -file c:\ca\ca-cert.pem -keystore %JAVA_HOME%\jre\lib\security\cacerts

keytool -import -v -trustcacerts -storepass as.1234 -alias blog_albertsong -file c:\ca\albertsong-cert.pem -keystore c:\ca\albertsong.jks


![CMD截图](http:https://img.haomeiwen.com/i555358/e66e3d5de232ea1a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![CMD截图](http://upload-images.jianshu.io/upload_images/555358-a3331dc162e48837.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![CMD截图](http://upload-images.jianshu.io/upload_images/555358-22b00edef793df29.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* albertsong.jks就是我们要用的证书
* 将albertsong.jks拷贝到tomcat   conf目录下,然后配置  tomcat   server.xml
* 在server.xml 里面找到  相应注释的标签,去掉注释配置如下。
 

<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150"
minSpareThreads="25"
maxSpareThreads="75"
SSLEnabled="true"
enableLookups="false"
disableUploadTimeout="true"
acceptCount="100"
scheme="https"
secure="true"
clientAuth="false"
sslProtocol="TLS"
keystoreType="JKS"
keystoreFile="C:\webInstall\Tomcat-7.0.59\conf\odin.jks" keystorePass="123456"/>


  * 
  * 
  * 

***













[相关下载] 
(openss.cfg配置文件)https://pan.baidu.com/s/1jIySexS
[相关拓展]
(tomcat+mysql配置)http://www.jianshu.com/p/49c2d9a5bf82
[参考资料]  
(openssl证书的生成)http://albertsong.iteye.com/blog/198344
(alt_names)http://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl/27931596#27931596
(extensions指令)
http://stackoverflow.com/questions/6194236/openssl-version-v3-with-subject-alternative-name
(证书格式)
http://www.blogjava.net/lihao336/archive/2011/08/18/356763.html
上一篇下一篇

猜你喜欢

热点阅读