本文原文地址 :https://www.jianshu.com/p/c3294887c6b6
nginx的配置比较简单,主要分以下三步:
1.安装Homebrew
2.安装nginx
3.验证结果
1.安装Homebrew
终端输入
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
大概过个二十分钟左右安装完成,其间提示输入密码,输入Mac密码,安装成功后就可以安装nginx了
![](http://upload-images.jianshu.io/upload_images/3003216-e4b0e5989daa811c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
2.安装nginx
终端输入
brew install nginx
这个比第一个快,我是一分钟完成的,完成后出现下图
![](http://upload-images.jianshu.io/upload_images/3003216-737ba8e419ff38e5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
这里我们选择依赖Homebrew安装nginx可以减少很多麻烦,细心的你会发现nginx安装过程中下了很多东西.
3.验证结果
安装好了,就可以启动nginx了,终端输入
brew services start nginx
![](http://upload-images.jianshu.io/upload_images/3003216-d93f4e1045e6034f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
启动成功,可以直接转到浏览器输入:
http://localhost:8080
![](http://upload-images.jianshu.io/upload_images/3003216-281f2c0fa6e48e33.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
如果出现上图所示,表面nginx安装并开启成功.
番外篇:
nginx默认安装到 /usr/local/ 目录下
![](http://upload-images.jianshu.io/upload_images/3003216-042f3ddcb03e0e11.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
终端输入:
/usr/local/Cellar/nginx
点击版本号文件夹进入html文件夹,里面有index.html和50x.html两个文件,我的全目录是 /usr/local/Cellar/nginx/1.13.12/html
在html文件夹里新建test.json文件,随便输入点内容
![](http://upload-images.jianshu.io/upload_images/3003216-2ace3fce3232b73d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp)
回到浏览器输入
http://localhost:8080/test.json
就能看到你刚创建的文件了
![](http://upload-images.jianshu.io/upload_images/3003216-2f7d5ae1c6e1bacf.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/988/format/webp)
nginx重启命令
brew services restart nginx
好了,到此结束了~~~