Nginx伺服器需要通過http_ssl_module模組來載入SSL認證,因此安裝SSL認證前,需要保證當前Nginx已包含此模組。
常見報錯
報錯1:the "ssl" parameter requires ngx_http_ssl_module
原因:當前Nginx伺服器未編譯http_ssl_module模組。
報錯2:nginx: [emerg] unknown directive “ssl” in /usr/local/nginx/conf/nginx.conf
原因:修改設定檔後,執行nginx -s reload報上述錯誤,表明目前的版本的Nginx未編譯http_ssl_module模組。
報錯3:./configure: error: SSL modules require the OpenSSL library
原因:缺少OpenSSL依賴庫。
解決方案
確認伺服器中已安裝了openssl,若當前Nginx未編譯http_ssl_module,還需重新編譯Nginx使其包含http_ssl_module。
樣本方案
說明
本文以CentOS 8.0 64位系統,Nginx 1.14.1版本,OpenSSL 1.1.1k版本為例。僅供參考,請根據Nginx的版本,選擇安裝相容的OpenSSL版本。
檢查目前的版本Nginx是否包含
http_ssl_module模組。執行以下命令,查看當前Nginx的編譯參數。
nginx -V | grep http_ssl_module如下圖所示,如果輸出中包含
--with-http_ssl_module字樣,即說明已經包含http_ssl_module模組,否則表示當前Nginx安裝版本中不包含該模組,您需要手動添加。
安裝
http_ssl_module。# CentOS為例,openssl 1.1.1k版本,請根據Nginx選擇相容的openssl版本。 sudo yum install openssl-devel-1.1.1k配置
http_ssl_module並編譯。# 前往Nginx安裝目錄(樣本目錄,請替換為實際的Nginx安裝目錄) cd /usr/local/nginx/ # 配置http_ssl_module,其他參數可自訂 ./configure --with-http_ssl_module # 編譯 sudo make重要注意不能make install,否則會覆蓋原有Nginx的配置。
再次檢查
http_ssl_module模組是否成功安裝。如果未成功安裝,請重複步驟2-3。nginx -V | grep http_ssl_module重啟Nginx服務。
# 進入Nginx服務的可執行目錄(樣本目錄,請以實際路徑為準)。 cd /usr/local/nginx/sbin # 重新載入設定檔。 ./nginx -s reload