Mac安装Nginx

1、检查homebrew是否安装,打开终端输入命令

man brew

如已安装,终端会输出一些命令的帮助信息,此时输入Q退出即可

BREW(1)
NAME
brew - The missing package manager for macOS
SYNOPSIS
brew --version
brew command [--verbose|-v] [options] [formula] ...
DESCRIPTION
Homebrew is the easiest and most flexible way to install the UNIX tools
Apple didn't include with macOS.
ESSENTIAL COMMANDS
For the full command list, see the COMMANDS section.
With --verbose or -v, many commands print extra debugging information.
Note that these flags should only appear after a command.
install formula
Install formula.
uninstall formula
:

如没安装,点击跳转下载

2、查看本机brew版本

brew --version

3、更新本机brew版本

brew --update

4、安装Nginx

brew install nginx

出现以下信息,表示安装成功

==> 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

 8080为默认端口。

查看nginx被安装的目录

查看nginx配置文件目录   
open /usr/local/etc/nginx/

查看nginx被安装到的目录 
open /usr/local/Cellar/nginx 

5、启动Nginx

nginx

验证是否启动成功

打开浏览器访问:localhost:8080

出现如下图,表示成功:

6、关闭Nginx

nginx -s stop
原文地址:https://www.cnblogs.com/hejianliang/p/13887946.html