xzhuz / blog-gitment

博客备份和comment记录
https://meisen.pro
0 stars 0 forks source link

使用Certbot升级Http到Https #11

Open xzhuz opened 6 years ago

xzhuz commented 6 years ago

https://meisen.pro/article/b49fd0ab40d94b4ea7f05332a3d67264

这几天收到了 Let's Encrypt Team的邮件,告知我的证书在20天内就要过期了。想了想,自从之前从http升级了Https之后就再也没有管过她了。乘着这封邮件的时机,总结一下自己从Http升级到Https的经历,以及这次是如何更新证书的。

说明

 如果大家现在使用的Google Chrome或Safari浏览器,那么大家可以在浏览器地址栏最左边的一把绿色的小锁。这个小锁标志说明你正在通过安全的Http协议访问该网站。如果访问没有使用SSL加密的HTTP网站,则会被浏览器标记不安全。当然,大家都不希望出现这种情况,所以接下来,我就来将Http升级到Https吧。

 本小站使用Certbot来升级Https,使用Certbot升级Https是很简单的,只需要跟着官方User Guide执行一连串指令即可。先说说我升级Https的网站部署环境,我的网站部署在Ubuntu16.04 的Nginx服务器上。说了这么多,下面我就要开始了。

安装Certbot

 要使用Certbot升级Https,最开始就是安装Certbot。

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install python-certbot-nginx 

 以上的指令相信经常使用Linux的同学已经很熟悉了吧。所以我们就直接进行下一步。

升级Https

$ sudo certbot --nginx

 这一行指令执行完之后,我们会得到一个certificate,并且cerbot会自动配置你的nginx配置文件nginx.conf,当然了你也可以手动配置你的nginx。

更新证书

 Let's Encrypt的certificates有效期只有90天,所以需要定时更新证书。更新证书就执行以下指令。

$ sudo certbot renew

 想要偷懒的话,可以只用自动更新的指令。

$ sudo certbot renew --dry-run

问题

 和之前在服务器上配置Nginx一样,总是没有一帆风顺的事情。做完事情要学会总结,我就来总结一下这次升级过程中我所遇到的问题吧。

问题一: 执行certbot —nginx报错

 问题核心描述: nginx: [error] invalid PID number "" in "/run/nginx.pid"

 问题解决办法:

  1)可以指定nginx.conf 文件启动 nginx -c /../nginx.conf

  2)简单粗暴:将pid放到 /run/nginx.pid. 通过ps -ef | grep nginx获取pid,echo 12137 >> /run/nginx.pid

问题二: 跟着官方文档配置不成功

 出现这个问题,我好方

 问题核心描述: 跟着官方文档指令配置不成功

 问题解决办法:

使用Certbot升级https不成功,那么换一个方式,我们使用certbot-auto

$ wget https://dl.eff.org/certbot-auto
$ chmod a+x ./certbot-auto
$ ./certbot-auto --help

安装好了之后,就可以直接安装了

./certbot-auto certonly --standalone --email xxx@163.com -d meisen.pro

执行这个指令的时候,我则是出现了报错。

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 2363, in <module>
    main()
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 719, in main
    symlink=options.symlink)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 988, in create_environment
    download=download,
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 918, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 812, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /opt/eff.org/certbot/venv/bin/python2.7 - setuptools pkg_resources pip wheel failed with error code 1

事情总是有解决办法的。

easy_install --upgrade virtualenv

总结

 以上则是我这次升级Https的历程,记录了当时遇到的一些错误,这里也将这些错误贴出来给大家作为参考。最后,如果大家有什么问题请大家在下方指出评论。

转载请说明出处

xzhuz commented 5 years ago

Attempting to renew cert (meisen.pro) from /etc/letsencrypt/renewal/meisen.pro.conf produced an unexpected error: Problem binding to port 80: Could not bind to IPv4 or IPv6.. Skipping. All renewal attempts failed. The following certs could not be renewed:

xzhuz commented 5 years ago

To fix these errors, please make sure that your domain name was entered correctly and the DNS A/AAAA record(s) for that domain contain(s) the right IP address.

xzhuz commented 5 years ago

重点: certbot --nginx 之前一定要停止nginx