本文主体为单向认证的配置方式,生成证书的方式放于最后附录里面。
实例中tomcat版本为tomcat9。
仅为tomcat时,进入tomcat目录/conf/server.xml中,添加如下代码(具体参数请根据实际情况修改),并重启tomcat即可。若使用自定义的证书查看时使用ie为佳,chrome会直接屏蔽域名访问的链接(提示"此网站无法提供安全连接",以致纠结好长时间以为自己配置失败了呢= =),ip访问一般都会提示非安全链接,点击忽略继续就好。
关键代码
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="C:\00Work\01Programming\01Java\JavaEE\localhost.keystore" keystorePass="123456"/>
clientAuth false(单向认证)/true(双向认证)
keystoreFile 证书所在目录
keystorePass 创建证书“keystore”的密码
nginx中在conf目录下的 nginx.conf文件中添加如下代码,tomcat目录/conf/server.xml中设置好相应domain即可。
关键代码
server {
listen 443;
server_name domain;#要访问https的域名
ssl on;
root html;
index index.html index.htm;
ssl_certificate C:/zhonya/keytool/ssl/domain.crt;
ssl_certificate_key C:/zhonya/keytool/ssl/domain.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
proxy_connect_timeout 240;
proxy_send_timeout 240;
proxy_read_timeout 240;
# note, there is not SSL here! plain HTTP is used
proxy_pass http://domain
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
1、CMD命令
keytool -genkeypair -alias "tomcat" -keyalg "RSA" -keystore "D:\wind\tomcat\keytool\tomcat.keystore" -validity 36500
2.输入密码等相应内容
此处暂时不再过多叙述,具体的可查看:
http://lixor.iteye.com/blog/1532655
keytool -genkeypair -alias "server" -keyalg "RSA" -keysize 1024 -keypass "windtomcat" -keystore D:\wind\tomcat\keytool\server.jks -storepass windtomcat -validity 36500 -dname "CN=域名1,CN=域名2,CN=域名3,OU=wind,O=SJ,L=test,ST=HB,C=CN"
据说这种方法可以生成多域名证书,由于当初在chrome中测试始终出现错误提示(本文开始时说的情况),最终没做过多验证。
参考地址:
http://www.xuebuyuan.com/371801.html
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有