mac 12.3系统 安装nginx

540 阅读2分钟

今天安装nginx的时候遇到了一些问题,整理如下

1、 安装brew

我之前安装过,brew -v查看版本

liru@lirudeMacBook-Pro my-youtubeclone-backend % brew -v
Homebrew 2.5.2

如果没有brew,使用一下命令安装或者自行google查看brew安装教程

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2、 安装nginx

使用brew安装的nginx的时候遇到问题如下

liru@lirudeMacBook-Pro my-youtubeclone-backend % brew install nginx
Warning: You are using macOS 12.3.
We do not provide support for this pre-release version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this pre-release version.

Error: The following directories are not writable by your user:
/usr/local/var/log

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/var/log

And make sure that your user has write permission.
  chmod u+w /usr/local/var/log

错误:说我没有写入/usr/local/var/log文件的权限,

解决办法:执行命令行中提示的命令

liru@lirudeMacBook-Pro my-youtubeclone-backend % sudo chown -R $(whoami) /usr/local/var/log

继续安装nginx

liru@lirudeMacBook-Pro my-youtubeclone-backend % brew install nginx                        
Warning: You are using macOS 12.3.
We do not provide support for this pre-release version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this pre-release version.

==> Downloading https://www.openssl.org/source/openssl-1.1.1g.tar.gz
######################################################################## 100.0%
==> Downloading https://ftp.pcre.org/pub/pcre/pcre-8.44.tar.bz2
curl: (6) Could not resolve host: ftp.pcre.org
Warning: Problem : timeout. Will retry in 1 seconds. 3 retries left.
curl: (6) Could not resolve host: ftp.pcre.org                                
Warning: Problem : timeout. Will retry in 2 seconds. 2 retries left.
curl: (6) Could not resolve host: ftp.pcre.org                                
Warning: Problem : timeout. Will retry in 4 seconds. 1 retries left.
curl: (6) Could not resolve host: ftp.pcre.org                                

Trying a mirror...
==> Downloading https://www.mirrorservice.org/sites/ftp.exim.org/pub/pcre/pcre-8.44.tar.bz2
######################################################################## 100.0%
==> Downloading https://nginx.org/download/nginx-1.19.2.tar.gz
######################################################################## 100.0%
==> Installing dependencies for nginx: openssl@1.1 and pcre
==> Installing nginx dependency: openssl@1.1
==> perl ./Configure --prefix=/usr/local/Cellar/openssl@1.1/1.1.1g --openssldir=/usr/local/etc/openssl@1.1 no-ssl3 no-ssl3-me
==> make
==> make test
Last 15 lines from /Users/liru/Library/Logs/Homebrew/openssl@1.1/03.make:
../test/recipes/95-test_external_boringssl.t ....... skipped: No external tests in this configuration
../test/recipes/95-test_external_krb5.t ............ skipped: No external tests in this configuration
../test/recipes/95-test_external_pyca.t ............ skipped: No external tests in this configuration
../test/recipes/99-test_ecstress.t ................. ok
../test/recipes/99-test_fuzz.t ..................... ok

Test Summary Report
-------------------
../test/recipes/80-test_ssl_new.t                (Wstat: 256 Tests: 29 Failed: 1)
  Failed test:  12
  Non-zero exit status: 1
Files=155, Tests=1460, 186 wallclock secs ( 1.54 usr  0.31 sys + 95.94 cusr 41.93 csys = 139.72 CPU)
Result: FAIL
make[1]: *** [_tests] Error 1
make: *** [tests] Error 2

Do not report this issue to Homebrew/brew or Homebrew/core!


Error: You are using macOS 12.3.
We do not provide support for this pre-release version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrew's GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience while you are running this pre-release version.

错误:这次提示说当前macOS版本不支持安装nginx,

解决办法:因为brew里的包有过时的(outdated),所以需要更新brew

...过程很多,把最后结果贴出来
You have 2 outdated formulae and 1 outdated cask installed.
You can upgrade them with brew upgrade
or list them with brew outdated.

错误:brew有2个过时的包

解决办法:执行brew upgrade

liru@lirudeMacBook-Pro my-youtubeclone-backend % brew upgrade

执行brew upgrade完成,再次尝试安装 brew install nginx,然后安装成功。

此时的brew版本为3.5.3

liru@lirudeMacBook-Pro my-youtubeclone-backend % brew -v
Homebrew 3.5.3

3、验证安装成功

浏览器访问 http://localhost:8080/ ,看见如下页面就表示nginx启动成功

111.png