1.需要安装Command Line tools
xcode-select --install
2.安装Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
大概过个二十分钟左右安装完成,其间提示输入密码,输入Mac密码,安装成功后就可以安装nginx了

homebrew
安装完成之后,建议执行一下自检,brew doctor如果看到Your system is ready to brew. 那么你的brew已经可以开始使用了。
自检过程中如果一下错误:

解决如下:https://www.jianshu.com/p/9118ee9da3b7
// 执行下面这句命令,更换为中科院的镜像:
git clone git://mirrors.ustc.edu.cn/homebrew-core.git/ /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core --depth=1
// 把homebrew-core的镜像地址也设为中科院的国内镜像
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
// 更新
brew update
// 使用
brew install node
3.安装nginx
brew install nginx
这个比第一个快,我是一分钟完成的,完成后出现下图

nginx install
这里我们选择依赖Homebrew安装nginx可以减少很多麻烦,细心的你会发现nginx安装过程中下了很多东西.
4.验证结果
安装好了,就可以启动nginx了,终端输入
brew services start nginx

start
启动成功,可以直接转到浏览器输入:

welcome
如果出现上图所示,表面nginx安装并开启成功.
番外篇:
nginx默认安装到 /usr/local/ 目录下

nginx
终端输入:
/usr/local/Cellar/nginx
点击版本号文件夹进入html文件夹,里面有index.html和50x.html两个文件,我的全目录是 /usr/local/Cellar/nginx/1.13.12/html
在html文件夹里新建test.json文件,随便输入点内容

回到浏览器输入
http://localhost:8080/test.json
就能看到你刚创建的文件了

test
nginx重启命令
brew services restart nginx
网友评论