Mac通过安装包安装NGINX服务

背景

使用 brew install nginx安装 NGINX,一直报一个错:

Error: nginx: Invalid bottle tag symbol

无论是在我更新了 home brew 后,错误依然存在。

建议

在毫无头绪的时候,建议去官网看看,说不定有什么发现。我就发现了,可以使用安装包的形式来安装,这样就可以不用依赖 brew 了。

另外又找了一篇 2014 年的博客,写了如何在 Mac 上通过安装包的形式安装 NGINX 。

教程

毕竟参考的是历史悠远的博客,少许内容跟现在有点差异,我这里提供在我的机器上操作的步骤给到大家,避免大家同我一样再踩坑!

Install Nginx

  1. Download the latest stable version – nginx 1.22.0.
  2. Unzip the downloaded package by the command “tar xvzf nginx-1.22.0.tar.gz”.
  3. “cd nginx-1.22.0”.
  4. “sudo ./configure”. There is an error displayed:

在第 4 步会遇到一个报错:

./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.
  1. To fix the error, visit the tutorial page and read “Building nginx from Sources”, in which you can find the link of PCRE library.
  2. Go to PCRE official site, and find the latest version of PCRE library on SourceForge.
  3. Download the package and unzip it by the command “tar xvzf pcre2-10.40.tar.gz”.
  4. Now, you can run the configure file again with the parameters ”sudo ./configure -–with-pcre= ”.
  5. Configuration is done.

PS:第 4 步需要切换到 NGINX 包目录下执行,path 为 PCRE 的安装包目录(使用绝对路径)

the default nginx path prefix is “/usr/local/nginx”.

  1. To install nginx, type in “sudo make install”.
  2. Find the executable file “cd /usr/local/nginx/sbin”
  3. Launch nginx “sudo ./nginx”

PS:第 1 步,需要在 NGINX 安装包路径下执行!

The nginx is successfully running now!

test nginx

NGINX 的默认监听端口为 80,按以上步骤启动后,直接在浏览器访问 127.0.0.1 或者 curl 127.0.0.1即可。

请求响应出现 Welcome to nginx!即代表 NGINX 安装成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值