1、 安装 certbot
wget /certbot-auto
chmod a+x certbot-auto
2、 申请ssl ,因为要验证你的域名是否解析到了你的服务器,会借用你的80/443端口。所以在执行下面语句之前保证80/443
是没有被占用的。我这里只需要关闭tomcat就行。
./certbot-auto certonly --standalone --email xxxxxx@ -d -d
这里是多域名的,想要在添加域名的话继续在后面添加 -d 域名 email后面填写的是你的邮箱
弹出的 两个选项 一个选择同意 A 另外一个选择 Y 就行。
等待到最后出现以下内容说明申请成功
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live//. Your cert
will expire on 2017-09-14. To obtain a new or tweaked version of
this certificate in the future, simply run certbot-auto again. To
non-interactively renew *all* of your certificates, run
"certbot-auto renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: /donate
Donating to EFF: /donate-le
说明申请成功,并且存放在了 这个文件下 /etc/letsencrypt/live//
3、 合成tomcat的证书,在 tomcat 底下创建一个文件夹用来存放准备生产的证书(当然也可以自己选择一个目录存放)
我的目录是:/usr/local/tomcat/conf/LetsEncrypt ,
#进入申请证书的目录,这个目录会以第一个域名明明,不影响多域名使用。
cd /etc/letsencrypt/live//
#复制到tomcat刚创建的证书目录下
cp /usr/local/tomcat/conf/LetsEncrypt
cp /usr/local/tomcat/conf/LetsEncrypt
#进入到这个目录
cd /usr/local/tomcat/conf/LetsEncrypt/
#生成.p12文件
openssl pkcs12 -export -in -inkey -out fullchain_and_key.p12 -name tomcat
这里会被要求设置密码,输入就行(下面用到的:yourPKCS12pass)
#生成.jks证书
keytool -importkeystore -deststorepass 'yourJKSpass' -destkeypass 'yourKeyPass' -destkeystore -srckeystore fullchain_and_key.p12
srcstoretype PKCS12 -srcstorepass 'yourPKCS12pass' -alias tomcat
其中 yourPKCS12pass 是上一步中设置的ssl证书密码,这里的yourKeyPass是要设置的keystore密码,可以与yourPKCS12pass一致,下面配置tomcat会用到
4、 配置tomcat
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="443" ></Connector>
<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true"
keystoreFile="/usr/local/tomcat/conf/LetsEncrypt/" keystorePass="证书的密码"
clientAuth="false" sslProtocol="TLS" ></Connector>
5、 完成,在tomcat创建两个站点,放入一个简单的.jsp文件,可以通过 即可访问。
免费证书只能用三个月,但是可以通过脚本自动更新,后续我会补充相关的自动更新的方法。
相关文章
- 【Centos】certbot+tomcat配置https访问
- nexus部署及配置https访问
- xxl-job使用nginx代理https后,访问出现403异常问题解决-这是之前的nginx配置:
- centos下配置Apache的https强制跳转
- Apache配置ssl证书-实现https访问
- CentOS7中MongoDB备份与恢复,配置远程访问
- springboot minio项目配置https后minio无法访问问题,minio配置https
- 宝塔 搭建HOJ 配置域名 反向代理 开启https访问
- Nginx配置——区分PC或手机访问不同域名以及http跳转https
- 【小程序】访问 https配置的数据接口