Centos Certbot 使用

  1. 安装
    可选配置:启动EPEL存储库 非必要项
go 复制代码
yum install -y epel-release
yum clean all
yum makecache
#启用可选通道  可以不配置
yum -y install yum-utils
yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional

必要配置参数:安装certbot

go 复制代码
yum -y install certbot python2-certbot-nginx
  1. 配置nginx
go 复制代码
upstream proxy {
    server 127.0.0.1:9000;
}
server {
    listen 443;
    server_name  test.test.com;
    location ~ ^/(base|admin|web|assets|auth|user) {
        proxy_redirect          off;
        proxy_set_header        X-Proxy-Client-IP $remote_addr;
        proxy_set_header        Host $http_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;
        proxy_pass              http://proxy;
    }
    location / {
        root /data/camc/public/dist;# project path
        try_files $uri /index.html;# if not match,go to the save page
        index  index.html index.htm;
    }

    error_page  404              /404.html;                                                                                                           
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }


}
#http直接重定向到https
server {
   listen 80;
   server_name test.test.com;
   rewrite ^(.*)$ https://$host$1 permanent;


}

或是一个正常的侦听80端口的也可以,重点是下一步生成证书,

  1. 生成证书

3.1自动配置nginx

运行如下命令会自动下载证书并配置nginx。

go 复制代码
certbot --nginx

会列表nginx下的域名列表,从其中选择2中配置的域名,会自动生成ssl文件并配置好443端口

3.2 手动配置nginx

运行如下命令会自动下载证书但需要自己配置nginx。

go 复制代码
certbot certonly --nginx

若nginx未安装在默认路径(/etc/nginx or /usr/local/etc/nginx)下需自己指定nginx路径,到conf目录

go 复制代码
certbot certonly --nginx --nginx-server-root=/root/nginx/conf
  1. 自动更新
go 复制代码
sudo crontab -e
go 复制代码
0 0 1 * * /usr/bin/certbot renew  >> /var/log/le-renew.log
相关推荐
Britz_Kevin6 分钟前
从零开始的云计算生活——第五十九天,基于Jenkins自动打包并部署Tomcat环境
运维·jenkins·生活
今晚务必早点睡13 分钟前
从零到上线:Docker、Docker Compose 与 Runtime 安装部署全指南(含实战示例与应用场景)
运维·docker·容器
snowfoootball31 分钟前
(自用)Linux 常用命令自查文档
linux·运维·服务器
墨染 殇雪1 小时前
webshell及冰蝎双击无法打开?
运维·服务器·webshell·webshell管理工具
R-G-B1 小时前
Linux常见命令总结 合集二:基本命令、目录操作命令、文件操作命令、压缩文件操作、查找命令、权限命令、其他命令
linux·基本命令·目录操作命令·linux常见命令·压缩文件操作·权限命令·查找命令
Chukai1231 小时前
Windows 和 Linux 系统下修改防火墙机制开放端口
linux·运维·windows
FL16238631291 小时前
[ubuntu][C++]onnxruntime安装cpu版本后测试代码
linux·c++·ubuntu
逻辑羊驼2 小时前
VSCode+MobaXterm+X11可视化界面本地显示
运维·服务器·ubuntu·3d
fendouweiqian2 小时前
nginx 反向代理使用变量的坑
运维·nginx
Zacks_xdc2 小时前
【前端】使用Vercel部署前端项目,api转发到后端服务器
运维·服务器·前端·安全·react.js