nginx 源碼安裝 mac

nginx源碼安裝,添加with-http_ssl_module, mac采坑記

首先,下載源碼,解壓,進nginx文件目錄,運行變以前的配置,這里因為需要nginx支持https服務(wù),故需加上--with-http_ssl_module參數(shù)

./configure  --with-http_ssl_module
  • 錯誤1

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library

下載pcre-8.40 解壓

tar -zxvf pcre-8.40.tar.gz

再次編譯

./configure  --with-http_ssl_module --with-pcre=../pcre-8.40
  • 錯誤2

./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.

  1. 安裝最新的opensslhttps://www.openssl.org/
tar -zxvf openssl-1.0.2l.tar.gz
  1. 在nginx源碼中建立一個bundle目錄,并把最新的OpenSSL源碼復(fù)制進來
tangliang?local/opt/nginx-1.13.1? mkdir bundle                  [0:06:39]
tangliang?local/opt/nginx-1.13.1? cp -R ../openssl-1.0.2l ./bundle

3.再次運行

./configure  --with-http_ssl_module --with-pcre=../pcre-8.40 --with-openssl=./bundle/openssl-1.0.2l --prefix=/usr/l

看似沒問題了,那就執(zhí)行下一步把

make install
  • 錯誤3

如果運行到此錯,算你運氣不好(暫時只在mac上出現(xiàn)了,在ubuntu上能順利通過),前面兩錯都得重新解決

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [objs/nginx] Error 1
make: *** [install] Error 2

執(zhí)行到這里,此錯事表示pcre的link階段出錯了

參考文檔
需要手動配置pcre的連接文件

因為之前是直接下載的源碼,對于pcre里面鏈接文件不好取到,所以這里用homebrew重新安裝pcre(之前下載的pcre包可以刪除了),(openssl不是必須的)

brew install pcre
brew install openssl

當取到最新的pcre包之后,鏈接文件就比較好拿到了,根據(jù)如下配置
重新生成編譯文件

export KERNEL_BITS=64  
./configure  --with-http_ssl_module  --with-openssl=./bundle/openssl-1.0.2l --prefix=/usr/local/opt/nginx --with-cc-opt='-I/usr/local/Cellar/pcre/8.40/include/' --with-ld-opt='-L/usr/local/Cellar/pcre/8.40/lib'

最后一步

make install

不出意外,這次應(yīng)該是ok了

為了使用方便,再為nginx添加一個軟連接

ln -s /usr/local/opt/nginx/sbin/nginx /usr/local/bin/nginx
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容