提交 7116b616 authored 作者: PGY's avatar PGY

feat(nginx): 为nginx部署添加自签名证书生成功能

- 检查证书文件是否存在,如果不存在则生成自签名证书
- 证书文件路径为/data/security/nginx_cert/server.crt和server.key
- 使用openssl生成2048位RSA自签名证书,有效期10年
- 通过san.cnf配置文件和v3_req扩展生成证书
- 添加相应的日志记录和错误处理机制
上级 c9cb3cca
......@@ -2783,6 +2783,38 @@ function nginx_x86() {
fi
log "INFO" "镜像加载成功"
# 检查证书文件是否存在,如果不存在则生成自签名证书
local cert_dir="/data/security/nginx_cert"
local cert_file="$cert_dir/server.crt"
local key_file="$cert_dir/server.key"
if [ ! -f "$cert_file" ] || [ ! -f "$key_file" ]; then
log "WARN" "证书文件不存在,正在生成自签名证书..."
# 进入证书目录
cd "$cert_dir" || {
log "ERROR" "无法进入证书目录 $cert_dir"
return 1
}
# 生成自签名证书
if ! openssl req -x509 \
-newkey rsa:2048 \
-nodes \
-keyout server.key \
-out server.crt \
-days 36500 \
-config san.cnf \
-extensions v3_req; then
log "ERROR" "证书生成失败"
return 1
fi
log "INFO" "证书生成成功"
else
log "INFO" "证书文件已存在,跳过生成"
fi
# 检查容器是否存在
if docker ps -a --format '{{.Names}}' | grep -qw "$nginx_container_name"; then
log "WARN" "容器 $nginx_container_name 已存在,自动退出部署操作!!!"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论