Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Created July 22, 2016 21:59
Show Gist options
  • Select an option

  • Save mohemohe/e08a15699357650343dc13c3c8eefa70 to your computer and use it in GitHub Desktop.

Select an option

Save mohemohe/e08a15699357650343dc13c3c8eefa70 to your computer and use it in GitHub Desktop.
proxy_passしててcertのrenewが面倒くさい系のletsencrypt
#!/usr/bin/zsh
#### 設定 ここから ################################################################################
# letsencrypt クライアント
client="/usr/bin/certbot"
# そのままrenewできる(静的|動的)サイト
sites1=(
# domain,/path/to/basedir
"ghippos.net,/svr/nginx/ghippos_net"
"media.ghippos.net,/svr/nginx/media_ghippos_net"
"anodesu.net,/svr/nginx/anodesu_net"
"butimi.li,/svr/nginx/butimi_li"
"hontodayo.net,/svr/nginx/hontodayo_net"
"kaboranai.de,/svr/nginx/kaboranai_de"
"elf.moe,/svr/nginx/elf_moe"
)
# proxy_passのみ設定していてそのままでは証明書が更新できないサイト
# /etc/nginx/sites-available にrenew用のconfがあるのを前提にしている
# 挙動は下を見て察してくれ
sites2=(
# domain,/path/to/basedir
"cloud.ghippos.net,/svr/nginx/cloud_ghippos_net"
"mail.elf.moe,/svr/nginx/mail_elf_moe"
)
#### 設定 ここまで ################################################################################
# 普通にいけるやつのrenew
for site in $sites1; do
echo ${(R)site%,*}
$client certonly --agree-tos --renew-by-default --webroot -w ${(R)site#*,} -d ${(R)site%,*}
done
# めんどくさいやつのrenew
for site in $sites2; do
# renew用のconfに切り替える
rm -f /etc/nginx/sites-enable/${(R)site%,*}
ln -s /etc/nginx/sites-available/${(R)site%,*}.renew /etc/nginx/sites-enable/${(R)site%,*}
# nginxの再読み込み
systemctl reload nginx
# renew
echo ${(R)site%,*}
$client certonly --agree-tos --renew-by-default --webroot -w ${(R)site#*,} -d ${(R)site%,*}
# 公開用のconfに切り替える
rm -f /etc/nginx/sites-enable/${(R)site%,*}
ln -s /etc/nginx/sites-available/${(R)site%,*} /etc/nginx/sites-enable/${(R)site%,*}
done
# nginxの再読み込み
systemctl reload nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment