网上大部分文章都是yum(Linux)或者用brew安装。本人机器macos 10.15.2,刚开始使用brew安装不成功,于是选择离线安装。安装Nginx需要用到pcre和openssl,需要提前准备这两个文件。
1.安装openssl
到官网下载安装包,解压后切换到openssl的目录,执行以下命令:
./config --prefix=/usr/local/openssl
看到以下信息表示配置成功。
**********************************************************************
*** ***
*** OpenSSL has been successfully configured ***
*** ***
*** If you encounter a problem while building, please open an ***
*** issue on GitHub <https://github.com/openssl/openssl/issues> ***
*** 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 file first) ***
*** ***
**********************************************************************
然后执行以下命令:
make && make install
接着是漫长的等待。如果提示权限:
Cannot create directory /usr/local/openssl: Permission denied
执行以下命令:
sudo chown -R $(whoami) /usr/local/
2.安装pcre
仍然采用离线的方式安装,到下面的地址下载安装包:
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.zip
解压后,切换到解压后的目录输入以下命令:
./configure --prefix=/usr/local/pcre --enable-utf8 --enable-unicode-properties
3.安装nginx
到nginx官网下载安装包解压,并切换到安装目录,执行以下命令:
./configure --prefix=/usr/local/nginx
然后屏幕呼呼啦啦一堆代码,最后几行如下:
/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
statically from the source with nginx by using --with-pcre=<path> option.
啊哈,出错了,提示缺少pcre库,刚才明明已经安装了,说明姿势不对,换个姿势重来。上面的命令不完整,需要指定pcre的目录和openssl的目录,但是这个目录不是安装后的目录,而是刚开始解压的后的位置。执行以下命令(注意with):
./configure --prefix=/usr/local/nginx --with-pcre=/Users/imac/software/pcre-8.36 --with-openssl=/Users/imac/software/openssl-1.1.1n
出现以下内容说明成功
Configuration summary
+ using PCRE library: /Users/imac/software/pcre-8.36
+ using OpenSSL library: /Users/imac/software/openssl-1.1.1n
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
执行以下命令:
make && make install
安装成功以后会在/usr/local下出现nginx目录
4、启动nginx
切换到/usr/local/nginx目录,执行以下命令
cd /usr/local/nginx
访问localhost,出现以下界面说明启动成功:

?
如果是用brew安装出现404,请切换源之后再安装:
brew install nginx
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/openssl%401
#=#=#
curl: (22) The requested URL returned error: 404
Error: Failed to download resource "openssl@1.1"
Download failed: https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/openssl%401.1-1.1.1g.catalina.bottle.tar.gz
清华源最近好像有问题,请参考另一篇文章macos中brew切换到阿里源_Apple_羊先森的博客-CSDN博客macos中brew切换到阿里源 https://blog.csdn.net/caicaimaomao/article/details/123662715
|