一、概述:
客户提交一个证书给我,让帮忙把网站域名都改为HTTPS,但是修改配置完成后,确出现如下错误。
<code>[root@localhost ssl]# /usr/local/nginx/sbin/nginx -t
nginx: [emerg] PEM_read_bio_X509_AUX("/usr/local/nginx/conf/ssl/server.pem") failed (SSL: error:0906D064:PEM routines:PEM_read_bio:bad base64 decode)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed/<code>
错误关键" error:0906D064:PEM routines:PEM_read_bio:bad base64 decode"
二、故障原因:
经过对关键字的排查,SSL证书公钥字符串每隔64个字符需要加一个换行,负责会提示 "error:0906D064:PEM routines:PEM_read_bio:bad base64 decode"
三、解决方法:
出现上述问题的原因,主要是由于客户提交给我的证书不是文件,直接用微信复制给我的内容,现在一般阿里云申请的证书自动生成的文件,直接使用文件就会避免出现这样的错误。
好了,出现错误还是要解决的。
首先,想办法把证书内容转换为每隔64个字符,加一个换行。
1、可以使用如下命令
<code>[root@dataX ~]# fold --help
Usage: fold [OPTION]... [FILE]...
Wrap input lines in each FILE (standard input by default), writing to
standard output.
Mandatory arguments to long options are mandatory for short options too.
-b, --bytes count bytes rather than columns
-c, --characters count characters rather than columns
-s, --spaces break at spaces
-w, --width=WIDTH use WIDTH columns instead of 80
--help display this help and exit
--version output version information and exit/<code>
2、执行语句如下
<code>[root@localhost ssl]# /usr/local/nginx/sbin/nginx -t
nginx: [emerg] PEM_read_bio_X509_AUX(“/usr/local/nginx/conf/ssl/server.pem”) failed (SSL: error:0906D064:PEM routines:PEM_read_bio:bad base64 decode)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
[root@localhost ssl]# fold -w 64 server.pem > server.pem1
[root@localhost ssl]# \\cp -rf server.pem1 server.pem
[root@localhost ssl]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ssl]# /usr/local/nginx/sbin/nginx -s reload/<code>
核心命令:fold -w 64 文件 >新文件。
如果上述文章对你有帮助,欢迎转发+关注哦。