一、概述:
客戶提交一個證書給我,讓幫忙把網站域名都改為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 文件 >新文件。
如果上述文章對你有幫助,歡迎轉發+關注哦。
閱讀更多 Linux運維技術之路 的文章