美文网首页
Windows系统下使用免费证书

Windows系统下使用免费证书

作者: 邪恶的正派 | 来源:发表于2021-01-20 16:11 被阅读0次

前几天在给用户处理网站事情的时候,他们不打算买证书,让我到let's encrypt申请一个免费的,三个月更新一次。
我之前也没弄过。用户的服务器是windows的,用的应用服务器也不是nginx,tomcat,使用的是jboss。我现在将整个处理过程记录下。

1 目的

将具有外网的域名添加免费证书,实现https访问。

2 具体步骤

到let's encrypt去申请免费证书,地址为:https://letsencrypt.org

2.1 安装配置certbot

  1. 下载地址

https://certbot.eff.org/lets-encrypt/windows-other

  1. 安装下载好的软件beta-installer-win32.exe

  2. 以管理员方式运行run.bat

  3. 停止运行的jboss服务器,同时保证jboss的端口80已经映射到域名了

  4. 运行命令

certbot certonly –standalone
  1. 根据提示,输入域名,输入自己的邮箱地址,方便提醒到期重新生成,因为这个证书只有免费3个月时间,命令执行完成后,生成文件夹,相关证书文件在C:\Certbot\live\域名名称 下,如图:


    image.png
  1. 将privkey.pem文件拷贝到另一个目录


    image.png

2.2 安装配置OpenSSL

  1. 到以下地址下载安装OpenSSL

http://slproweb.com/products/Win32OpenSSL.html

  1. 安装后如图所示
image.png
  1. 安装后进入bin目录,以管理员方式运行openssl.exe

  2. 执行以下命令,将pem证书转换为pfx证书,会提示输入密码

pkcs12 -export -out D:\home\sckq.pfx -in C:\Certbot\live\scsty.cn\fullchain.pem -inkey D:\home\privkey.pem

转换后如图所示:

image.png

2.3 配置https

  1. 进入到jboss的server.xml目录,配置证书
<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
         keystoreFile="D:/home/sckq.pfx" 
                 keystorePass="密码"
         keystoreType="PKCS12"
               clientAuth="false" sslProtocol="TLS" URIEncoding="utf-8" />
``
  1. 配置默认跳转到https,打开web.xml,在该文件末尾处</welcome-file-list>标签后面加上这样一段,配置如下
<login-config> 
        <!-- Authorization setting for SSL  --> 
        <auth-method>CLIENT-CERT</auth-method> 
        <realm-name>Client Cert Users-only Area</realm-name> 
    </login-config> 
    <security-constraint> 
        <!-- Authorization setting for SSL  --> 
        <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>

  1. 配置完成后,重启jboss。

可以看到证书是安全的了,3个月后到期。等到期的时候再生成一次证书,转换一次就可以了。

最后,感谢这篇文章博主提供的方法,将pem文件转pfx文件,文章链接
PEM文件和private.key文件生成Tomcat服务器所需的jks文件(配置SSL用)

相关文章

网友评论

      本文标题:Windows系统下使用免费证书

      本文链接:https://www.haomeiwen.com/subject/qcmkzktx.html