ngix-0x00-编译源码

1 下载源码

1
2
3
4
5
6
7
8
9
git clone git@github.com:Bannirui/nginx.git
cd ngix
git remote add upstream git@github.com:nginx/nginx.git
git remote set-url --push upstream no_push
git remote -v
git fetch upstream
git checkout master
git rebase upstream/master
git checkout -b my_study

2 前置依赖

2.1 brew安装

1
brew install pcre openssl

2.2 源码安装zlib

从官网下载源码

1
2
3
mkdir -p ~/MyApp/zlib
cp ~/Downloads/zlib-1.3.1.tar.gz ./
tar -zxvf ./zlib-1.3.1.tar.gz

那么zlib的home路径为/Users/dingrui/MyApp/zlib/zlib-1.3.1

3 配置编译选项

1
2
3
4
5
bash ./auto/configure \
--prefix=/usr/local/nginx \
--with-pcre \
--with-zlib=/Users/dingrui/MyApp/zlib/zlib-1.3.1 \
--with-openssl=/opt/homebrew/Cellar/openssl@3/3.4.1

4 编译

1
make

5 安装

1
sudo make install

然后在上面prefix指定的路径下可以看到可执行文件/usr/local/nginx/nginx

6 启动

配置文件在/usr/local/nginx/conf下,就用默认的配置就行

1
sudo /usr/local/nginx/sbin/nginx

服务默认监听在80端口


ngix-0x00-编译源码
https://bannirui.github.io/2025/02/20/nginx/nginx-0x00-编译源码/
作者
dingrui
发布于
2025年2月20日
许可协议