为你的网站安装免费的 SSL TLS 证书

前言

申请了很久的域名没有用起来怎么行呢?而访问安全需要获得一个可信的https证书颁发机构的认证,这其实是一个提升你网站可信度的方法,有很多的证书颁发机构,收费也高低不等,今天主要是介绍一个免费的https证书颁发机构ACME,以及如何给自己的网站进行认证。

准备工作

下载执行官方脚本

curl https://get.acme.sh | sh

source ~/.bashrc

我这里是root用户执行的,在家目录中生成了.acme.sh这个文件夹:

[root@csv tmp 13:26:34]#ll /root/.acme.sh/
total 256
-rw-r--r-- 1 root root    450 Jun  7 16:33 account.conf
-rwxr-xr-x 1 root root 223427 Jun  6 15:16 acme.sh
-rw-r--r-- 1 root root     78 Jun  6 15:16 acme.sh.csh
-rw-r--r-- 1 root root     78 Jun  6 15:16 acme.sh.env
drwxr-xr-x 4 root root     66 Jun  6 15:33 ca
drwxr-xr-x 2 root root   4096 Jun  6 15:16 deploy
drwxr-xr-x 2 root root   8192 Jun  6 15:16 dnsapi
-rw-r--r-- 1 root root   1307 Jun  7 16:33 http.header
drwxr-xr-x 2 root root   4096 Jun  6 15:16 notify

编辑account.conf文件:

# 添加自己邮箱
ACCOUNT_EMAIL='xxx@**.com'

# 添加阿里云Secret及秘钥
SAVED_Ali_Key='xxxxxxxxxx-key'
SAVED_Ali_Secret='xxxxxxxxx-secret'

阿里云Secret及秘钥的操作参考:创建阿里云AccessKey_访问控制(RAM)-阿里云帮助中心 (aliyun.com)

证书申请

执行脚本前请先关闭Nginx服务:

nginx -s stop

申请证书:

acme.sh --issue --set-default-ca --server letsencrypt -d templex.com -d *.templex.com

这时就会在当前目录下生成新的证书文件目录templex.com_ecc:

[root@csv tmp 13:26:34]#ll /root/.acme.sh/
total 256
-rw-r--r-- 1 root root    450 Jun  7 16:33 account.conf
-rwxr-xr-x 1 root root 223427 Jun  6 15:16 acme.sh
-rw-r--r-- 1 root root     78 Jun  6 15:16 acme.sh.csh
-rw-r--r-- 1 root root     78 Jun  6 15:16 acme.sh.env
drwxr-xr-x 4 root root     66 Jun  6 15:33 ca
drwxr-xr-x 2 root root   4096 Jun  6 15:16 deploy
drwxr-xr-x 2 root root   8192 Jun  6 15:16 dnsapi
-rw-r--r-- 1 root root   1307 Jun  7 16:33 http.header
drwxr-xr-x 2 root root   4096 Jun  6 15:16 notify
drwxr-xr-x 3 root root    196 Jun  6 15:41 templex.com_ecc

# 证书文件
[root@csv .acme.sh 13:49:25]#ll templex.com_ecc/
total 28
drwxr-xr-x 2 root root    6 Jun  6 15:41 backup
-rw-r--r-- 1 root root 1827 Jun  6 15:35 ca.cer
-rw-r--r-- 1 root root 3344 Jun  6 15:35 fullchain.cer
-rw-r--r-- 1 root root 1517 Jun  6 15:35 templex.com.cer
-rw-r--r-- 1 root root  856 Jun  6 15:41 templex.com.conf
-rw-r--r-- 1 root root  497 Jun  6 15:34 templex.com.csr
-rw-r--r-- 1 root root  210 Jun  6 15:34 templex.com.csr.conf
-rw------- 1 root root  227 Jun  6 15:34 templex.com.key

设置证书自动更新:

acme.sh --upgrade --auto-upgrade

证书安装

新建证书存放目录并导出证书文件:

# 新建
mkdir -p /data/cert/templex.com/

# 导出
acme.sh --install-cert -d templex.com --cert-file /data/cert/templex.com/templex.com.crt --key-file /data/cert/templex.com/templex.com.key --fullchain-file /data/cert/templex.com/fullchain.crt

Nginx配置

server {
    listen       443 ssl;
    server_name  abs.templex.com;

    ssl_certificate      /data/cert/templex.com/templex.com.crt;
    ssl_certificate_key  /data/cert/templex.com/templex.com.key;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    # location / {
    #     root   html;
    #     index  index.html index.htm;
    # }
	location / {
		proxy_pass http://xxx.xx.x.x:30000; 
	}
}

最后重启Nginx,再次访问一下abs.templex.com,再也没有显示不安全的链接了,算是大功告成。

nginx -s reload
nginx

参考:

申请并部署免费的 SSL/TLS 证书 - 莱布尼茨 - 博客园 (cnblogs.com)

ACME.SH 申请SSL证书(免费、自动更新)_adding txt value:-CSDN博客

相关推荐

  1. 网站安装免费 SSL TLS 证书

    2024-06-08 21:24:07       11 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-08 21:24:07       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-08 21:24:07       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-08 21:24:07       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-08 21:24:07       20 阅读

热门阅读

  1. STP简介

    2024-06-08 21:24:07       8 阅读
  2. 低代码开发赋能教育数字化及典型场景

    2024-06-08 21:24:07       11 阅读
  3. 【数据结构】单链表-->详细讲解,后赋源码

    2024-06-08 21:24:07       11 阅读
  4. android 异屏同显二.

    2024-06-08 21:24:07       8 阅读
  5. 2014年上海高考作文题目(ChatGPT版)

    2024-06-08 21:24:07       12 阅读
  6. golang定时器使用示例

    2024-06-08 21:24:07       12 阅读
  7. 前端常见的加密方式

    2024-06-08 21:24:07       8 阅读
  8. input输入框设置样式

    2024-06-08 21:24:07       9 阅读
  9. Ansible——fetch模块

    2024-06-08 21:24:07       9 阅读