萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 電腦基礎知識 >  >> 電腦基本常識

安裝 Nginx 報錯怎麼辦?缺少 PCRE、OpenSSL 依賴的完整解決方案

在 Linux 環境下從原始碼編譯安裝 Nginx 時,./configure 階段常因缺少依賴庫而報錯。本文整理最常見的兩個錯誤與對應的 yum 安裝指令,助你一次通過編譯。

常見錯誤 1:缺少 PCRE 库

./configure: error: the HTTP rewrite module requires the PCRE library.

解決方法:

yum -y install pcre-devel

常見錯誤 2:缺少 OpenSSL 库

./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.

解決方法:

yum -y install openssl openssl-devel

一鍵安裝所有必要依賴並完成編譯安裝

為避免遺漏,建議一次安裝所有常用依賴:

yum -y install pcre-devel openssl openssl-devel zlib-devel gcc make

標準編譯安裝流程

  1. wget https://nginx.org/download/nginx-1.24.0.tar.gz(請自行換成最新穩定版連結)
  2. tar -zxvf nginx-1.24.0.tar.gz && cd nginx-1.24.0
  3. ./configure --prefix=/usr/local/nginx
  4. make && make install

安裝完成後,主程式位於 /usr/local/nginx/sbin/nginx,設定檔為 /usr/local/nginx/conf/nginx.conf。

補充說明

  • 若需支援 HTTP/2、gzip 等模組,configure 時可加入 --with-http_v2_module --with-http_gzip_static_module 等參數。
  • 生產環境建議使用官方預編譯套件(如 yum install nginx 或官方 repo),較易維護更新。
copyright © 萬盛學電腦網 all rights reserved