关于本机:
macOS:Monterey
处理器:Apple M1 Pro
下载所需依赖包
安装Pcre
-
解压并进入该目录
-
su root 输入密码
-
./configure --help
Installation directories: --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local]
By default, make install will install all the files in
/usr/local/bin', /usr/local/lib' etc.You can specify an installation prefix other than /usr/local' using --prefix', for instance --prefix=$HOME -
./configure --prefix=/Users/xxxx/SourceCode/pcre-8.45
若不指定安装目录直接make && make install 会默认安装到 /usr/local
-
make && make install
-
make -k check
安装openssl
-
版本选择:openssl-3.0.0.tar.gz (SHA256) (PGP sign) (SHA1)
-
解压并进入该目录
-
su root 输入密码
-
./config --h 若想详细了解安装细则请打开文件
INSTALL.md(从步骤可以省略)Configuring OpenSSL version 3.0.0 for target darwin64-arm64 Using os-specific seed configuration Creating configdata.pm Running configdata.pm Creating Makefile.in Creating Makefile
*** OpenSSL has been successfully configured ***
*** If you encounter a problem while building, please open an *** *** issue on GitHub github.com/openssl/ope… *** *** and include the output from the following command: ***
*** perl configdata.pm --dump ***
*** (If you are new to OpenSSL, you might want to consult the *** *** 'Troubleshooting' section in the
INSTALL.mdfile first) *** -
./config --prefix=/Users/xxxx/SourceCode/openssl-3.0.0
-
make && make install
cp: /Users/xxxxx/Downloads/openssl-3.0.0/include/openssl/aes.h and ./include/openssl/aes.h are identical (not copied). make: *** [install_dev] Error 1 (这个错是在复制过程中发现文件已经存在,但是貌似不影响Nginx使用具体也不找到答案)
我尝试在第5步配置如下,再次执行第6步仍然报错,配置如下:
./config --prefix=/Users/xxxxx/Downloads/openssl-3.0.0 --with-zlib-include=/Users/xxxxx/Downloads/openssl-3.0.0/openssl-include
我能理解这个错我大概需要把复制的文件指定到另一个地方需要一个配置参数,但是翻看
INSTALL.md也未能找到答案,若你能解决请在评论区告诉一下 -
openssl version 检查版本号
sh-3.2# openssl version LibreSSL 2.8.3
安装zlib
-
解压并进入该目录
-
su root 输入密码
-
./configure --help (目录里并没有找到安装说明,根据安装Pcre经验判断类似)
usage: configure [--const] [--zprefix] [--prefix=PREFIX] [--eprefix=EXPREFIX] [--static] [--64] [--libdir=LIBDIR] [--sharedlibdir=LIBDIR] [--includedir=INCLUDEDIR] [--archs="-arch i386 -arch x86_64"]
-
./configure --prefix=/Users/xxxx/SourceCode/zlib-1.2.11
-
make && make install
-
make -k check
安装Nginx
-
下载地址:sourceforge.net/projects/li…
下载版本:nginx-1.20.0.tar.gz
-
解压并进入该目录
-
su root 输入密码
-
./configure --help
-
./configure --conf-path=/usr/local/nginx/nginx.conf --prefix=/Users/xxxxx/SourceCode/nginx --with-pcre=/Users/xxxxx/SourceCode/pcre-8.45 --with-zlib=/Users/xxxxx/SourceCode/zlib-1.2.11 --with-openssl=/Users/xxxxx/SourceCode/openssl-3.0.0 --with-http_stub_status_module --with-http_ssl_module
--conf-path=/usr/local/nginx/nginx.conf
一般会单独指定一个存放配置文件的地方,将安装目录与源码目录区分下
-
make &&make install
安装完成后通过软链接将源码目录下得/Users/xxxxx/SourceCode/nginx/sbin/nginx 链接到安装目录内,也可以直接链接目录即可
-
修改nginx.conf 文件
只修改第一行,保证运行没问题,具体配置根据实际开发来调整
将 #user nobody 打开并修改位user root staff
-
配置环境变量
启动前可以配置环境变量
如:
export NGINX_HOME=/usr/local/nginx export PATH=NGINX_HOME/bin
记得 source 一下
-
启动nginx
nginx -c /usr/local/nginx/nginx.conf
-
访问 localhost:80 即可