最近一直纠结一个情况,访问http://www自动跳转到https://,而访问https://www提示证书问题。这是因为我的网站只添加了xiaosiseo.com的ssl证书,而没添加www.xiaosiseo.com的ssl证书。今天找到了一个可以不改变网站其他内容,即不重新部署ssl及网站环境的方法,直接添加一个www.xiaosiseo.com的证书到xiaosiseo.com证书中,下面开始讲解。
前提条件:添加了www的A解析记录,即将WWW解析到ip地址。
首先,在终端输入如下命令:
certbot certonly --cert-name xiaosiseo.com -d xiaosiseo.com,www.xiaosiseo.com
以上代码表示,仅更新证书,将xiaosiseo.com证书替换为xiaosiseo.com及www.xiaosiseo.com证书。然后稍等片刻,出现如下反馈:
Saving debug log to /var/log/letsencrypt/letsencrypt.log How would you like to authenticate with the ACME CA? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: Spin up a temporary webserver (standalone) 2: Place files in webroot directory (webroot) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
这里,我们选择第二个选项,即输入2,摁下回车:
Renewing an existing certificate Performing the following challenges: http-01 challenge for xiaosiseo.com http-01 challenge for www.xiaosiseo.com Input the webroot for xiaosiseo.com: (Enter 'c' to cancel): /data/www/xiaosiseo.com(这里输入你的网站根目录)
得到如下反馈:
Select the webroot for www.xiaosiseo.com: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: Enter a new webroot 2: /data/www/xiaosiseo.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2(选择第二个即可)
等待自动安装完毕证书,重启服务器即可完成证书刷新:
当然,你也可以直接重启apache或者nginx。
当然,如果你发现你访问不带WWW的https页面时,无法访问,提示证书问题。也可以根据本站教程设置,输入如下代码即可,前提也是要添加A记录才可以。
certbot certonly --cert-name www.xiaosiseo.com -d www.xiaosiseo.com,xiaosiseo.com
不管是带www还是不带www,最好都可以访问网站!
© 版权声明
THE END
暂无评论内容