Mac OS 源码编译安装Nginx

下载软件

访问地址: https://nginx.org 根据自己的需求下载合适的安装包

up-f597d880a7c4274793fb6c093a557969ec3.png

首先建个临时目录 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脚本时报如下错误:

up-be075f32a0ffa3d3edd7ae410b1f57d3d35.png

尝试执行 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

猜你喜欢

转载自blog.csdn.net/qq_25231683/article/details/131658573