前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >啊,原来申请数字证书这么简单

啊,原来申请数字证书这么简单

作者头像
云水木石
发布2021-04-22 10:23:37
7330
发布2021-04-22 10:23:37
举报

数字证书在公开密码算法中扮演着重要的角色,可用于数字签名、密钥协商、身份认证等等。如果要部署 HTTPS 网站,首先就要申请数字证书。

提到数字证书,人们可能会想到高大上的 CA中心、繁琐的申请流程、高昂的价格。虽然很多安全专家都警告 HTTP 的安全问题,呼吁全站采用 HTTPS,谷歌甚至在 Chrome 浏览器中将所有未部署 HTTPS 的网站都标记为不安全,但目前还有很多网站没有采用 HTTPS。

这周在阿里云上申请了一个云主机,尝试着部署 HTTPS,发现其实申请证书并部署 HTTPS 超级简单。

首先需要澄清的是,数字证书并不是都需要花钱。Let's Encrypt就是一个完全免费的CA机构,他是个非赢利的组织。为了推动HTTPS网站的部署,截至2020年底,Let's Encrypt就已经为2.4亿网站签发了证书,影响力越来越大。Let's Encrypt 签发的证书兼容性非常好,大部分浏览器和操作系统都支持。

而且,Let's Encrypt设计了一套证书管理的标准协议,使得整个申请过程不需要人工干预,自动化完成。

下面就说说具体如何操作,云主机采用的操作系统是 Ubuntu 20.04。

  1. 安装Certbot。
代码语言:javascript
复制
$ sudo snap install --classic certbot
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
  1. 申请证书
代码语言:javascript
复制
$ sudo certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): mogoweb@126.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Account registered.
No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated)  (Enter 'c' to cancel): www.ilego.club
Requesting a certificate for www.ilego.club
Performing the following challenges:
http-01 challenge for www.ilego.club
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/default
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/default

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://www.ilego.club
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/www.ilego.club/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/www.ilego.club/privkey.pem
   Your certificate will expire on 2021-06-30. To obtain a new or
   tweaked version of this certificate in the future, simply run
   certbot again with the "certonly" option. To non-interactively
   renew *all* of your certificates, run "certbot renew"
 - 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

不敢相信,两个步骤就搞定。我试着访问我部署的网站 https://www.ilego.club ,成功了!

因为我的 WEB 服务器使用的是 nginx,所以 certbot 后面带的是 --nginx 参数。certbot 会自动找到 nginx 的配置文件,并对配置文件进行修改。查看了一下,配置文件主要增加了如下内容:

代码语言:javascript
复制
server {

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
    server_name www.ilego.club; # managed by Certbot


        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}


    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.ilego.club/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.ilego.club/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = www.ilego.club) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 ;
        listen [::]:80 ;
    server_name www.ilego.club;
    return 404; # managed by Certbot


}

可以看到,不仅配置了 HTTPS,还将 HTTP 请求重定向到 HTTPS。

Let's Encrypt证书默认有效期是90天,但certbot自动为系统增加了一个自动化任务,到期自动给原有证书续期(renew)。

可能会有人疑惑,这么简单,安全性如何?

根据审核的宽松程度,数字证书可以分为三种类型,分别是DV证书、OV证书、EV证书。

  • DV(Domain Validated)证书是最常见的一种证书类型,比如Let's Encrypt只会签发DV证书,申请证书的CSR请求会包含域名信息,CA机构获取CSR请求后,从中取出域名,校验域名的所有权,如果域名所有者就是证书申请者,代表身份审核通过,申请者有权申请该域名(包含子域名)对应的证书。
  • OV(Organization Validated)证书,CA机构会对申请者的身份进行严格的审核,从而给用户(浏览器)提供更安全的信任。CA根据严格的标准会审核申请者身份,比如说审核申请者的企业资质、企业地址等消息,确保申请者的身份是真实的。
  • EV(Extended Validation)证书,CA机构会对申请者的身份进行更严格的审核,对于CA机构来说,CA机构会严格根据CA/Browser论坛制定的标准审核申请者的身份,该标准称为Baseline Requirement标准,是由浏览器厂商、CA等机构创建的。

一般来说,DV证书更适合于个人、中小企业网站,企业和政府机构一般会申请OV证书,而银行、电商企业通常会申请EV证书。

好了,关于申请数字证书并为网站配置 HTTPS 就聊到这,有没有考虑也将自己个人或公司的网站也升级到 HTTPS ?

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2021-04-02,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 云水木石 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云服务器
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档