Mac os安装nginx 使用homebrew无法下载安装包问题

问题场景:

笔者使用Mac mojave 系统,通过homebrew 安装nginx。

问题描述:

安装nginx的命令如下:

brew install nginx

执行命令后如下错误:

AntonyZhang:~ zwq$ brew install nginx
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/openssl%401.1-1.1.1k.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/pcre-8.44.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/nginx-1.19.9.mojave.bottle.tar.gz

curl: (22) The requested URL returned error: 404 
Trying a mirror...
==> Downloading https://ghcr.io/v2/homebrew/core/bottles/nginx-1.19.9.mojave.bottle.tar.gz
==> Downloading from https://github.com/-/v2/packages/container/package/homebrew%2Fcore%2Fbottles%2Fnginx-1.19.9.mojave.bottle.tar.gz
Warning: Transient problem: timeout Will retry in 1 seconds. 3 retries left.
Warning: Transient problem: timeout Will retry in 2 seconds. 2 retries left.
Warning: Transient problem: timeout Will retry in 4 seconds. 1 retries left.

curl: (28) Connection timed out after 15002 milliseconds
Error: Failed to download resource "nginx"
Download failed: https://ghcr.io/v2/homebrew/core/bottles/nginx-1.19.9.mojave.bottle.tar.gz

原因分析:

根据返回的报错信息,大致可以知道,是因为网络的原因导致的,即homebrew的下载源是外网的,因此下载速度很慢或者会导致下载失败。

解决方案:

根据「刘悦的技术博客」 Mac os:将Homebrew的下载源换成国内镜像增加下载速度(阿里云镜像). 通过替换仓库的地址 完美解决了问题。

解决步骤如下:

1. 替换仓库地址:

1)替换brew.git
执行命令:

cd "$(brew --repo)"
git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git

2)替换homebrew-core.git
执行命令:

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
2. 更新下载地址:

执行更新命令:

brew update

执行该命令后,会打印许多更新的目录和文件。

3. 再执行brew install nginx
AntonyZhang:homebrew-core zwq$ brew install nginx
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/openssl%401.1-1.1.1k.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/pcre-8.44.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/nginx-1.19.10.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Installing dependencies for nginx: openssl@1.1 and pcre
==> Installing nginx dependency: openssl@1.1
==> Pouring openssl@1.1-1.1.1k.mojave.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> /Users/zwq/.bash_profile

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> Summary
🍺  /usr/local/Cellar/openssl@1.1/1.1.1k: 8,071 files, 18.4MB
==> Installing nginx dependency: pcre
==> Pouring pcre-8.44.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/pcre/8.44: 204 files, 5.5MB
==> Installing nginx
==> Pouring nginx-1.19.10.mojave.bottle.tar.gz
==> Caveats
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:
  brew services start nginx
Or, if you don't want/need a background service you can just run:
  nginx
==> Summary
🍺  /usr/local/Cellar/nginx/1.19.10: 25 files, 2.1MB
==> Caveats
==> openssl@1.1
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> /Users/zwq/.bash_profile

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> nginx
Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To have launchd start nginx now and restart at login:
  brew services start nginx
Or, if you don't want/need a background service you can just run:
  nginx

nginx基本知识

1.安装目录

cd /usr/local/Cellar/nginx

2.配置文件目录

cd /usr/local/etc/nginx

3.查看默认端口号
在路径/usr/local/etc/nginx下的nginx.conf文件中:
nginx.conf
4.启动nginx
1)进入到启动脚本所在目录,笔者安装的nginx版本是1.19.10

cd /usr/local/Cellar/nginx/1.19.10/bin

2)启动nginx

./nginx

3)查看进程

AntonyZhang:bin zwq$ ps aux|grep nginx
zwq              41531   0.0  0.0  4268056    808 s000  S+    8:09下午   0:00.00 grep nginx
zwq              41525   0.0  0.0  4292524   1028   ??  S     8:09下午   0:00.00 nginx: worker process
zwq              41524   0.0  0.0  4292076    532   ??  Ss    8:09下午   0:00.00 nginx: master process ./nginx

4)访问验证
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值