最近折腾http2,因为宝塔面板的openssl还是1.0.1的版本,而chrome需要到1.0.2以后的版本才支持。此脚本根据宝塔面板的文件目录撰写,可以根据自己的需要修改相应的下载安装目录。另外需要注意的是,如数据资料多,把rm改成mv转移原openssl文件以防万一。

#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
run_path="/root"

Install_OpenSSL()
{
    openssl_status=`cat /www/server/lib.pl | grep openssl`
    if [ "${openssl_status}" != 'openssl_installed' ]; then
        cd ${run_path}
        wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz -T 20
        tar xvf openssl-1.0.2l.tar.gz
        rm -f openssl-1.0.2l.tar.gz
        cd openssl-1.0.2l
        ./config --prefix=/usr shared zlib-dynamic
        rm -f /usr/bin/openssl
        rm -f /usr/include/openssl
        make && make install
        ln -sf /usr/include/openssl/*.h /usr/include/
        ln -sf /usr/lib/openssl/engines/*.so /usr/lib/
        ldconfig -v
        echo -e "openssl_installed" >> /www/server/lib.pl
        openssl version
        
        cd .. 
        rm -rf openssl-1.0.2l
    fi
}

while [ "$go" != 'y' ] && [ "$go" != 'n' ]
do
    read -p "Do you really want to upgrade OpenSSL to 1.0.2l?(y/n): " go;
done
if [ "${go}" == 'n' ];then
    echo 'Your alrea cancel the upgrade.';
    exit 1;
fi

Install_OpenSSL

保存脚本,执行命令:

wget -O openssl.sh http://your-domain/openssl.sh && sh openssl.sh

chrome地址栏输入以下命令检测http2是否生效:

chrome://net-internals/#http2