https如何利用工具ssl证书;使用自己生成的证书
一、背景
多年前,我曾经搭建过邮箱服务器,其中搭建邮箱服务器其中生成SSL证书;
- 自己肆意生成的证书,网页https可能校验不过,仍然报不安全;
- 于是我用开源的项目工具生成SSL证书,通过了。
- 现在做Agent接入第三方时,发现需要https,现在把文档写出来
- 建议自己项目或测试开发与测试环境使用,
禁用生产、省的背锅
二、方式一
-
安装依赖
sudo snap install core sudo snap refresh core sudo snap install --classic certbot
-
生成证书(两条命令均可)
sudo certbot certonly --webroot -w /var/www/html -d depthswap.com -d mail.depthswap.com zhangjunbo0405@163.com 条款y 向你发邮件n
sudo certbot certonly --webroot -w /var/www/html -d depthswap.com --email zhangjunbo0405@163.com --agree-tos --no-eff-email
-
如果生成失败:配置nginx
location /.well-known/acme-challenge
,重启nginx,重新生成证书
使用
systemctl
重启 Nginx:sudo systemctl restart nginx
使用service
重启 Nginx:sudo service nginx restart
查看nginx
语法是否正确:sudo nginx -t
root@AIdemo2-clone:/# vim /etc/nginx/conf.d/travel.conf server {listen 80;server_name depthswap.com;location /.well-known/acme-challenge/ {root /var/www/html;} }
-
如何配置证书;
配置nginx,重启nginx
server {listen 80;server_name depthswap.com;# Redirect all HTTP requests to HTTPSreturn 301 https://$host$request_uri; }server {listen 443 ssl;server_name depthswap.com;ssl_certificate /etc/letsencrypt/live/depthswap.com/fullchain.pem;ssl_certificate_key /etc/letsencrypt/live/depthswap.com/privkey.pem;ssl_protocols TLSv1.2 TLSv1.3;ssl_ciphers HIGH:!aNULL:!MD5;location / {proxy_pass http://localhost:8090;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;} }
二、 生成SSL证书方式二
- 时间长了有点忘了,几乎与上面差不多
curl https://get.acme.sh | sh ~/.acme.sh/acme.sh --register-account -m zhangjunbo0405@163.com ~/.acme.sh/acme.sh --issue -d depthswap.com --webroot /var/www/html ~/.acme.sh/acme.sh --installcert -d depthswap.com --key-file /etc/pki/tls/private/privkey.key --fullchain-file /etc/pki/tls/certs/fullchain.crt