背景

公司需要网站需要使用https,由此诞生来需求。。。 系统: centos7.8 + nginx

介绍

Let’s Encrypt 是 一个叫 ISRG ( Internet Security Research Group ,互联网安全研究小组)的组织推出的免费安全证书计划。参与这个计划的组织和公司可以说是互联网顶顶重要的先驱,除了前文提到的三个牛气哄哄的发起单位外,后来又有思科(全球网络设备制造商执牛耳者)、 Akamai 加入,甚至连 Linux 基金会也加入了合作,这些大牌组织的加入保证了这个项目的可信度和可持续性 官方网站)

前提

  • 能够ssh访问服务
  • 80端口正常访问服务
  • 能通过互联网访问网站

    使用方法

  • 打开网站,输入对应软件及系统平台,此处我选择的是 NginxCentos7

image.png

  • ssh到服务器并安装 ```shell sudo yum install epel-release sudo yum install snapd sudo systemctl enable —now snapd.socket sudo ln -s /var/lib/snapd/snap /snap

sudo snap install core; sudo snap refresh core sudo snap install —classic certbot sudo ln -s /snap/bin/certbot /usr/bin/certbot sudo certbot —nginx # 此时,会进入交互式模式

[root@localhost nginx]# sudo certbot —nginx Saving debug log to /var/log/letsencrypt/letsencrypt.log Enter email address (used for urgent renewal and security notices) (Enter ‘c’ to cancel): admin@126.com … 中间省略…一路Y也是可以的 Which names would you like to activate HTTPS for?


1: demo.com 2: www.demo.com


Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter ‘c’ to cancel): # 会自动查找你的nginx配置文件,找到 server_name;回撤即可,此处需要此域名能通过或联网进行访问 ….

sudo certbot renew —dry-run # 测试下自动更新证书日期.

次数贴上 nginx 80 端口配置

  1. server {
  2. listen 80 default_server;
  3. listen [::]:80 default_server;
  4. server_name www.demo.com demo.com;
  5. root /usr/share/nginx/html;
  6. # Load configuration files for the default server block.
  7. include /etc/nginx/default.d/*.conf;
  8. location / {
  9. }
  10. error_page 404 /404.html;
  11. location = /404.html {
  12. }
  13. error_page 500 502 503 504 /50x.html;
  14. location = /50x.html {
  15. }
  16. }

```