一,安装homebrew
必须安装了homebrew,可在终端输入命令brew -v查看是否已经安装,没安装的话安装一下:

如果未安装先安装(网上很多文章)
二,查看nginx是否存在
使用命令:brew search nginx查看nginx是否存在:

不存在的话,就使用brew install nginx进行安装.
查看nginx安装成功:

三,查看nginx的安装信息

可以看到我nginx的配置存放路径就是:
/opt/homebrew/etc/nginx/nginx.conf
四,启动nginx:
cd /opt/homebrew/Cellar/nginx/1.25.1_1/bin
然后执行nginx:

打开浏览器的localhost:8080就可以看到了:

五,关闭nginx
cd /opt/homebrew/Cellar/nginx/1.25.1_1/bin
nginx -s stop