nginx添加https模塊


nginx添加https模塊

在配置文件nginx.conf,開啟了https監聽后,nginx -t檢查報錯如下,表明ssl參數需要使用ngx_http_ssl_module

nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module

檢查現有模塊

查看nginx已安裝的模塊,說明沒有http_ssl_module模塊

nginx -V
...
configure arguments: --prefix=/usr/local/nginx --with-stream --without-http_gzip_module --without-http_rewrite_module

開啟http_ssl_module模塊要加上--with_http_ssl_module,即configure arguments修改成

--prefix=/usr/local/nginx --with-stream --without-http_gzip_module --without-http_rewrite_module --with-http_ssl_module

nginx開啟ssl模塊

進入到nginx源碼目錄下,進行

cd /opt/nginx-1.20.0

#進行編譯前的檢查
./configure --prefix=/usr/local/nginx --with-stream --without-http_gzip_module --without-http_rewrite_module --with-http_ssl_module

由於沒有安裝openssl-devel組件,檢查未通過,根據報錯SSL modules require the OpenSSL library,知道了nginx的ssl模塊需要openssl庫,使用包管理工具安裝.對於類似的報錯情況,可根據錯誤提示自行處理

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
yum install -y openssl-devel

再次進行檢查,直到echo $?返回狀態碼為0,表示通過檢查,進行下一步

./configure --prefix=/usr/local/nginx --with-stream --without-http_gzip_module --without-http_rewrite_module --with-http_ssl_module
echo $?
0

進行編譯

make

這里不要進行make install,否則就是覆蓋安裝

備份nginx可執行文件

然后備份原有已安裝好的nginx

cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

關閉nginx,替換可執行文件

然后將剛剛編譯好的nginx覆蓋掉原有的nginx(這個時候nginx要停止狀態)

之前對nginx做了單元文件配置,可以通過系統命令控制nginx服務

沒有做單元配置的,直接使用原始命令操作即可

兩條命令執行一個就可以

#關閉nginx
systemctl stop nginxd.service
#nginx原始命令
nginx -s stop

#強制覆蓋nginx可執行文件
\cp ./objs/nginx /usr/local/nginx/sbin/nginx

檢查nginx模塊

查看nginx模塊參數,可以看到已經加載了--with-http_ssl_module參數

nginx -V
...
configure arguments: --prefix=/usr/local/nginx --with-stream --without-http_gzip_module --without-http_rewrite_module --with-http_ssl_module

檢查nginx配置

nginx檢查配置文件是否有錯誤,沒有問題,就可以對外提供https服務

nginx -t

參考鏈接

https://www.cnblogs.com/ghjbk/p/6744131.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM