一、問題現象
服務器nginx配置SSL證書后啟動報錯:
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:53
二、問題分析
原因:nginx缺少http_ssl_module模塊,編譯安裝的時候帶上–with-http_ssl_module配置就行了,但是現在的情況是我的nginx已經安裝過了,怎么添加模塊?以我的nginx為例子
①nginx的安裝目錄是/usr/local/nginx這個目錄,
②我的源碼包在/usr/local/nginx-1.20.2目錄,根據你自己實際情況對應自己的目錄
三、解決過程
1、如果是使用yum 安裝等方式,找不到源碼包,需要下載當前安裝相同版本的源碼包:
wget http://nginx.org/download/nginx-1.8.0.tar.gz
使用nginx -V
查詢當前Nginx的編譯配置信息,configure arguments: 后面為當前運行Nginx的配置信息
(base) [root@iZxpl4sxxnloovZ nginx-1.8.0]# nginx -V nginx version: nginx/1.8.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) configure arguments: --prefix=/usr/local/nginx
2、 切換到源碼目錄執行如下代碼:
cd /usr/local/nginx-1.20.2 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
執行結果如下(內容比較多):
3、編譯 : make
(這里不要進行make install,否則就是覆蓋安裝)
[root@llc nginx-1.19.10]# make
4、 進入到nginx目錄,備份原來nginx配置文件
[root@i-h7ei19cd conf]# pwd
/usr/local/nginx/conf
[root@i-h7ei19cd conf]# cp nginx.conf nginx.conf.bak
cp: overwrite ‘nginx.conf.bak’? y
5、保證nginx是關閉狀態,如果無法關閉,用kill命令強制殺死進程
6、復制剛編譯生成的配置覆蓋原有的配置
進入到源碼包目錄,然后找到nginx,copy到nginx對應安裝目錄,命令如下:
7、切換到nginx安裝目錄
cd /usr/local/nginx/sbin
8、啟動nginx
[root@i-h7ei19cd sbin]# pwd /usr/local/nginx/sbin [root@i-h7ei19cd sbin]# ./nginx
9、打開頁面,nginx正常啟動
10、配置ssl模塊,對nginx.conf文件進行編輯,編輯完,保存。如下:
11、驗證配置文件是否正確,並啟動nginx
[root@i-h7ei19cd sbin]# ls nginx nginx.old [root@i-h7ei19cd 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@i-h7ei19cd sbin]# ./nginx -s reload
12、打開瀏覽器,輸入地址,驗證ssl是否配置成功: