解決一次由於SSL證書到期導致的網站不能訪問的問題(Nginx,php,Apache)

1. 現象

放假期間收到zabbix報警,提示主站訪問不了,報502。


2.排查思路及過程

因爲是過年休息,放假前又沒有更新,基本可以排除是更新和配置導致的問題。ssh連上服務器發現服務器連接和資源都沒問題。這是一套lnamp架構的網站,就是nginx反向代理到Apache,所以考慮是Apache的問題,於是重啓httpd服務。


重啓httpd服務的時候啓動失敗,沒有看到錯誤,所以去查看日誌文件,看到如下報錯:

tail -200 /var/log/httpd/error_log

[TIME 2016] [error] SSL Library Error: -8181 Certificate has expired
[TIME 2016] [error] Unable to verify certificate 'Server-Cert'. Add "NSSEnforceValidCerts off" to nss.conf so the server can start until the problem can be resolved.

可以看到是證書過期了,並且給出了一種解決方法是添加‘NSSEnforceValidCerts off’到nss.conf服務器就可以啓動,就是不驗證證書過期時間。


Apache是用https需要mod_nss的模塊支持,我的理解就是使用https需要安裝mod_nss,下面給一個官方說明:

   The mod_nss module provides strong cryptography for the Apache Web server via the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols using the Network Security Services (NSS) security library.


我的解決方法是重新生成新的證書

cd /etc/httpd/alias
#刪除舊的證書
rm -f *.db
#創建新證書
/usr/sbin/gencert /etc/httpd/alias > /etc/httpd/alias/install.log 2>&1
#查看證書信息
certutil -d /etc/httpd/alias -L -n Server-Cert
Certificate:
Data:
    Version: 3 (0x2)
    Serial Number: 3 (0x3)
    Signature Algorithm: PKCS #1 SHA-1 With RSA Encryption
    Issuer: "CN=Certificate Shack,O=example.com,C=US"
    Validity:
        Not Before: Mon Feb 15 02:05:10 2016
        Not After : Sat Feb 15 02:05:10 2020

現在可以看到證書的有效期是4年,新生成的證書到2020年過期。httpd服務可以正常啓動。


啓動httpd服務後發現首頁還是不能訪問,可以確認服務都正常啓動配置沒有問題。繼續查看httpd的錯誤日誌發現了新的報錯:

[TIME 2016] [error] SSL Library Error: -8038 SEC\_ERROR\_NOT\_INITIALIZED  
[TIME 2016] [error] NSS_Initialize failed. Certificate database: /etc/httpd/alias.


百度了下發現是權限問題,重新授下權搞定。

chown root.apache /etc/httpd/alias/*.db
chmod 0640 /etc/httpd/alias/*.db
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章