IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    【资源】分享一个lnmp后补SSL的sh脚本

    yumanutong发表于 2018-06-30 09:05:01
    love 0

    忙?懒?反正我是赶在最后一天来处理自己网站的SSL的。哦,我还有好几个站呢。所以,写了个.sh脚本,就不用一个个去折腾啦。代码筛选(整理)摘录自lnmp脚本。所以本文只能算分享。哈哈哈。这样不需要重新去执行一次lnmp vhost add来重新添加。没啥问题。

    首先在任意目录,你喜欢就好,我在 /root/lnmp1.x/目录下。

    1. cd /root/lnmp1.x
    2. vi add_ssl.sh

    然后按下insert按钮,进行插入如下内容:

    1. Echo_Yellow()
    2. {
    3.   echo -n $(Color_Text "$1" "33")
    4. }
    5. Color_Text()
    6. {
    7.   echo -e " \e[0;$2m$1\e[0m"
    8. }
    9. domain=""
    10.     while :;do
    11.         Echo_Yellow "Please enter domain(example: www.lnmp.org): "
    12.         read domain
    13.         if [ "${domain}" != "" ]; then
    14.                 echo " Your domain: ${domain}"
    15.             break
    16.         else
    17.             Echo_Red "Domain name can't be empty!"
    18.         fi
    19.     done
    20.     Echo_Yellow "Enter more domain name(example: lnmp.org *.lnmp.org): "
    21.     read moredomain
    22.     if [ "${moredomain}" != "" ]; then
    23.         echo " domain list: ${moredomain}"
    24.     fi
    25.     vhostdir="/home/wwwroot/${domain}"
    26.     echo "Please enter the directory for the domain: $domain"
    27.     Echo_Yellow "Default directory: /home/wwwroot/${domain}: "
    28.     read vhostdir
    29.     if [ "${vhostdir}" == "" ]; then
    30.         vhostdir="/home/wwwroot/${domain}"
    31.     fi
    32.     echo "Virtual Host Directory: ${vhostdir}"
    33.     email=""
    34.     while :;do
    35.         Echo_Yellow "Please enter Administrator Email Address: "
    36.         read email
    37.         if [ "${email}" == "" ]; then
    38.             Echo_Red "Administrator Email Address cannot be empty!"
    39.         else
    40.             echo "Server Administrator Email:${email}"
    41.             break
    42.         fi
    43.     done
    44.     letsdomain=""
    45.         if [ "${moredomain}" != "" ]; then
    46.             letsdomain="-d ${domain}"
    47.             for i in ${moredomain};do
    48.                 letsdomain=${letsdomain}" -d ${i}"
    49.             done
    50.         else
    51.             letsdomain="-d ${domain}"
    52.         fi
    53. wget https://dl.eff.org/certbot-auto --no-check-certificate -O /bin/certbot
    54. chmod +x /bin/certbot
    55.         if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
    56.             yum -y install epel-release
    57.         fi
    58. country=`curl -sSk --connect-timeout 10 -m 60 https://ip.vpser.net/country`
    59.     if [ "${country}" = "CN" ]; then
    60.         if [ -s ~/.pip/pip.conf ]; then
    61.             grep "index-url" ~/.pip/pip.conf
    62.             echo "pip.conf exist."
    63.         else
    64.             echo "Create pip.conf..."
    65.             mkdir ~/.pip
    66.             cat > ~/.pip/pip.conf <<EOF
    67. [global]
    68. index-url = https://pypi.doubanio.com/simple/
    69. [install]
    70. trusted-host=pypi.doubanio.com
    71. EOF
    72.         fi
    73.         sed -i 's#pypi.python.org/packages#pypi.doubanio.com/packages#g' /bin/certbot
    74.     fi
    75. echo "Starting create SSL Certificate use Let's Encrypt..."
    76.     /bin/certbot certonly --email ${email} --agree-tos -n --webroot -w ${vhostdir} ${letsdomain}
    77.     lets_status=$?
    78.     if [ "${lets_status}" = 0 ]; then
    79.         Check_Lets_Cron
    80.         echo "Let's Encrypt SSL Certificate create successfully."
    81.     else
    82.         Echo_Red "Let's Encrypt SSL Certificate create failed!"
    83.     fi
    84. Check_Lets_Cron()
    85. {
    86.     if crontab -l|grep -q "/bin/certbot renew --disable-hook-validation";then
    87.         echo "Let's encrypt crontab renew rule is exist."
    88.     else
    89.         echo "Add Let's encrypt crontab renew rule..."
    90.         (crontab -l ; echo '0 3 */7 * * /bin/certbot renew --disable-hook-validation --renew-hook "/etc/init.d/nginx reload"') | crontab -
    91.     fi
    92. }

    然后按下ESC按钮退出编辑,ctrl+Q组合然后输入wq保存文件。

    1. #执行权限设置
    2. chmod +x add_ssl.sh
    3. #执行脚本
    4. ./add_ssl.sh

    然后根据提示操作输入域名,输入要一起签约的域名,然后还有就是现在网站所在的路径,和邮箱。然后就可以执行了。如果报错根据错误提示百度解决或者付费找我解决。

    关于wordpress、opencart等配置SSL。百度很多,,不过我也可以开一篇来写。done.



沪ICP备19023445号-2号
友情链接