(openresty)NGINX使用的OPENSSL版本过低导致的ERR_SSL_PROTOCOL_ERROR问题


最近公司电脑访问后台管理页面经常会出现ERR_SSL_PROTOCOL_ERROR的问题,但用家里电脑发现又能正常访问,确认chrome浏览器版本都为最新,排除浏览器问题,最后发现问题来自于服务端的openssl版本过低(1.0.1),升级到1.1.1过后即可恢复正常

原因

由于sha-1加密已经不再安全, 所以比较新的电脑系统都开始拒绝使用sha-1加密的ssl连接,因此才会出现ERR_SSL_PROTOCOL_ERROR(此网站无法提供安全连接)的错误信息。

解决方案

  1. 首先安装1.1.1版本的openssl

    wget https://www.openssl.org/source/openssl-1.1.1n.tar.gz
    tar zxvf openssl-1.1.1n.tar.gz
    cd openssl-1.1.1n/
    ./config --prefix=/usr/local/openssl1-1-1n
    make
    sudo make install

    安装完成过后使用/usr/local/openssl1-1-1n/bin/openssl version查看当前版本, 如果没出问题的话,应该就出问题了,可能会出现error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory的错误提示

    需要在/etc/ld.so.conf中加入/usr/local/openssl1-1-1n/lib
    然后执行sudo ldconfig
    再试试/usr/local/openssl1-1-1n/bin/openssl version
    正常情况的话就会显示OpenSSL 1.1.1n 15 Mar 2022
    然后备份老的opensslsudo mv /usr/bin/openssl /usr/bin/openssl.bak
    使用新的openssl软连接到原来的openssl路径上, sudo ln -s /usr/local/openssl1-1-1n/bin/openssl /usr/bin/openssl
    至此,openssl安装完毕

  2. 编译安装新的openresty

    wget https://openresty.org/download/openresty-1.21.4.3.tar.gz
    tar zxvf openresty-1.21.4.3.tar.gz
    cd openresty-1.21.4.3/
    ./configure --prefix=/usr/local/openresty_new
    # 如果上面的configure提示: you need to have ldconfig in your PATH env when enabling luajit.,请先执行export PATH=$PATH:/sbin后再重新configure
    make
    # 如果在make时提示undefined reference to `SSL_set0_verify_cert_store'错误,请使用./configure --prefix=/usr/local/openresty_new --with-openssl=openssl的源码目录, 比如: ./configure --prefix=/usr/local/openresty_new --with-openssl=/home/xiaoc/temp/openssl-1.1.1n
    sudo make install

    到这里openresty就安装完成了,使用/usr/local/openresty_new/nginx/sbin/nginx -V查看对应的openssl版本信息,同时记得修改默认nginx.conf配置文件以便能够正常使用,我这边是直接将老的nginx.conf复制过来的,具体情况需要根据自己的需求决定。

发表评论

您的电子邮箱地址不会被公开。