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
相关推荐
YH_DevJourney34 分钟前
Linux-C/C++《C/8、系统信息与系统资源》
linux·c语言·c++
威哥爱编程1 小时前
Linux驱动开发13个实用案例
linux
去看日出1 小时前
Linux(centos)系统安装部署MySQL8.0数据库(GLIBC版本)
linux·数据库·centos
qq_448941081 小时前
10、k8s对外服务之ingress
linux·容器·kubernetes
D-river2 小时前
【如何基于Debian构建Kali Linux】
linux·网络·安全·网络安全
年轮不改3 小时前
ARM-Linux 基础项目篇——简单的视频监控
linux·arm开发
m0_748238783 小时前
Nginx 负载均衡详解
运维·nginx·负载均衡
EasyNVR3 小时前
EasyRTC:全平台支持与自研算法驱动的智能音视频通讯解决方案
运维·服务器·小程序·音视频·webrtc·p2p·智能硬件
程序员JerrySUN4 小时前
树莓派 4B:AI 物联网完整部署方案
linux·人工智能·嵌入式硬件·物联网·分类·数据挖掘
柳鲲鹏4 小时前
Ubuntu编译ZLMediaKit
linux·运维·ubuntu