伍佰目录 短网址
  当前位置:海洋目录网 » 站长资讯 » 站长资讯 » 文章详细 订阅RssFeed

使用Let's Encrypt免费证书实现https

来源:本站原创 浏览:111次 时间:2022-08-25

使用Let's Encrypt免费证书实现https

Let's Encrypt是一家免费、开放、自动化的证书颁发机构(CA),为公众的利益而运行(由非盈利组织互联网安全研究小组(ISRG)运营)。

前提:你需要有自己的域名

生成证书的方式有很多种,详情点击这里。
我这里以Certbot来生成证书。

(1)、选择证书服务对象和操作系统


选择完后下拉就会出现具体的操作步骤,如下:

(2)、安装epel源

yum install epel-release -y

其他操作系统及其安装方法可以点这里。

(3)、安装certbot

yum install certbot python2-certbot-nginx

(4)、生成证书

可以选择两种方式。
第一种,直接生成证书并配置NGINX。

certbot --nginx

第二种,只生成证书,NGINX需要自己配置

certbot certonly --nginx

我选择的第二种,输出详情如下:

[root@VM_0_2_centos ssl]# certbot certonly --nginxSaving debug log to /var/log/letsencrypt/letsencrypt.logPlugins selected: Authenticator nginx, Installer nginxEnter email address (used for urgent renewal and security notices) (Enter 'c' tocancel): coolops@163.comStarting new HTTPS connection (1): acme-v02.api.letsencrypt.org- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Please read the Terms of Service athttps://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You mustagree in order to register with the ACME server athttps://acme-v02.api.letsencrypt.org/directory- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(A)gree/(C)ancel: A- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Would you be willing to share your email address with the Electronic FrontierFoundation, a founding partner of the Let's Encrypt project and the non-profitorganization that develops Certbot? We'd like to send you email about our workencrypting the web, EFF news, campaigns, and ways to support digital freedom.- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(Y)es/(N)o: YStarting new HTTPS connection (1): supporters.eff.orgWhich names would you like to activate HTTPS for?- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -1: jenkins.coolops.cn2: www.coolops.cn- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Select the appropriate numbers separated by commas and/or spaces, or leave inputblank to select all options shown (Enter 'c' to cancel): 1Obtaining a new certificatePerforming the following challenges:http-01 challenge for jenkins.coolops.cnWaiting for verification...Cleaning up challengesIMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at:   /etc/letsencrypt/live/jenkins.coolops.cn/fullchain.pem   Your key file has been saved at:   /etc/letsencrypt/live/jenkins.coolops.cn/privkey.pem   Your cert will expire on 2020-08-23. To obtain a new or tweaked   version of this certificate in the future, simply run certbot   again. To non-interactively renew *all* of your certificates, run   "certbot 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:   https://letsencrypt.org/donate   Donating to EFF:                    https://eff.org/donate-le

安装步骤执行即可,当看到如上输出信息,则表明证书签发成功。
我们可以到相应的目录下查看证书

[root@VM_0_2_centos jenkins.coolops.cn]# cd /etc/letsencrypt/live/jenkins.coolops.cn[root@VM_0_2_centos jenkins.coolops.cn]# ll total 4lrwxrwxrwx 1 root root  42 May 25 14:50 cert.pem -> ../../archive/jenkins.coolops.cn/cert1.pemlrwxrwxrwx 1 root root  43 May 25 14:50 chain.pem -> ../../archive/jenkins.coolops.cn/chain1.pemlrwxrwxrwx 1 root root  47 May 25 14:50 fullchain.pem -> ../../archive/jenkins.coolops.cn/fullchain1.pemlrwxrwxrwx 1 root root  45 May 25 14:50 privkey.pem -> ../../archive/jenkins.coolops.cn/privkey1.pem-rw-r--r-- 1 root root 692 May 25 14:50 README
注意:证书是有过期时间的,默认是3个月,我们可以使用脚本自动续约(见后文)。

(5)、配置NGINX

 server{         listen 80 ;         listen 443 ssl;         server_name jenkins.coolops.cn;         ssl_certificate /etc/letsencrypt/live/jenkins.coolops.cn/fullchain.pem;         ssl_certificate_key /etc/letsencrypt/live/jenkins.coolops.cn/privkey.pem;         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;         ssl_prefer_server_ciphers  on;         ssl_session_cache    shared:SSL:1m;         ssl_session_timeout  5m;         location / {                 proxy_connect_timeout 180;                 proxy_send_timeout 180;                 proxy_read_timeout 180;                 proxy_set_header Host $host;                 proxy_set_header X-Forwarder-For $remote_addr;                 proxy_pass http://127.0.0.1:8080;         } }

然后浏览器访问,并查看证书信息如下:

(6)、配置证书自动续签

官方已经提供了,直接加入cron即可。

echo "0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew -q" | sudo tee -a /etc/crontab > /dev/null


  推荐站点

  • At-lib分类目录At-lib分类目录

    At-lib网站分类目录汇集全国所有高质量网站,是中国权威的中文网站分类目录,给站长提供免费网址目录提交收录和推荐最新最全的优秀网站大全是名站导航之家

    www.at-lib.cn
  • 中国链接目录中国链接目录

    中国链接目录简称链接目录,是收录优秀网站和淘宝网店的网站分类目录,为您提供优质的网址导航服务,也是网店进行收录推广,站长免费推广网站、加快百度收录、增加友情链接和网站外链的平台。

    www.cnlink.org
  • 35目录网35目录网

    35目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向35目录推荐、提交优秀网站。

    www.35mulu.com
  • 就要爱网站目录就要爱网站目录

    就要爱网站目录,按主题和类别列出网站。所有提交的网站都经过人工审查,确保质量和无垃圾邮件的结果。

    www.912219.com
  • 伍佰目录伍佰目录

    伍佰网站目录免费收录各类优秀网站,全力打造互动式网站目录,提供网站分类目录检索,关键字搜索功能。欢迎您向伍佰目录推荐、提交优秀网站。

    www.wbwb.net