下載軟件
訪問地址:https://nginx.org 根據自己的需求下載合適的安裝包
首先建個臨時目錄 nginx-src 並下載所需軟件的源碼進行配置
mkdir nginx-src
cd nginx-src
wget https://nginx.org/download/nginx-1.18.0.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
wget https://www.openssl.org/source/openssl-1.1.0g.tar.gz
tar zxvf *.gz
cd nginx-1.18.0
./configure --with-pcre=../pcre-8.41/ --with-http_ssl_module --with-openssl=../openssl-1.1.0g --prefix=/Users/summergao/nginx
這裏我們將 nginx 安裝在 /Users/summergao/nginx 目錄下,prefix 指定的路徑請使用絕對路徑
錯誤處理
如果在執行 configure腳本時報如下錯誤:
嘗試執行 gcc 出如下錯誤
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools),
missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
執行:xcode-select --install 根據界面提示操作
繼續安裝
./configure --with-pcre=../pcre-8.41/ --with-http_ssl_module --with-openssl=../openssl-1.1.0g --prefix=/Users/summergao/nginx
可看到相關信息如下:
Configuration summary
+ using PCRE library: ../pcre-8.41/
+ using OpenSSL library: ../openssl-1.1.0g
+ using system zlib library
開始編譯安裝
make
make install
啓動 Nginx 並測試
由於默認的 nginx 運行在 80 端口上,因此需要有管理員的權限:
cd ../../nginx
sudo sbin/nginx