Uninote
Uninote

脚本所在服务器地址

121.196.47.141 路径:/usr/local/nginx/conf/vhost/module/auto_cert.sh

使用脚本批量生成证书

  • 脚本内容
#!/bin/bash
cd `dirname $0`
declare -i count
[ $# -ne 1 ] && echo "please inspect host prefix" && exit 2
cp ./cert.conf ../cert.conf
[ $? -ne 0 ] && echo "../cert.conf file exist" && exit 2
sed -i "s#prefix#$1#g" ../cert.conf
/usr/local/nginx/sbin/nginx -t || exit 2
/usr/local/nginx/sbin/nginx -s reload
[ ! -f certbot-auto ] && wget https://dl.eff.org/certbot-auto && chmod +x certbot-auto
for i in `grep server_name ../cert.conf |grep -v on.rongyipiao.com |awk '{print $2}'|sed 's#;##g'`
do
./certbot-auto certonly --no-self-upgrade --webroot -w /tmp -d $i && ((count ++))
done
[ $count -ne 5 ] && echo "all cert suessful" || echo "$count cert sucessful"
rm -f ../cert.conf
/usr/local/nginx/sbin/nginx -s reload
  • 脚本依赖文件(文件名必须为cert.conf且放在和上面脚本同层)
server {
 server_name prefix.www.dajxyl.com;
root /tmp;
}
server {
 server_name prefix.admin.dajxyl.com;
root /tmp;
}
server {
 server_name prefix.m.dajxyl.com;
root /tmp;
}
server {
 server_name prefix.api.dajxyl.com;
root /tmp;
}
server {
 server_name prefix.staffapi.dajxyl.com;
root /tmp;
}
server {
 server_name prefix.mirror.dajxyl.com;
root /tmp;
}
server {
 server_name prefix.s.dajxyl.com;
root /tmp;
}

使用范例

bash auto_cert.sh t1
# auto_cert.sh为脚本名称
# t1是域名前缀,脚本将结合cert.conf配置和调用cert-auto脚本生成t1.admin/m/api/staffapi/mirror/s/www.dajxyl.com这些域名的ssl证书

证书续期

auto_nginxconf

点赞(0) 阅读(1) 举报
目录
标题