以下是在 macOS 上安装 Nginx 的步骤:

1、打开终端(Terminal)应用程序。

2、安装 Homebrew,Homebrew 是一个包管理器,可以轻松安装 Nginx。在终端中输入以下命令:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

3、安装 Nginx。在终端中输入以下命令:

brew install nginx
默认安装路径:
/usr/local/Cellar/nginx/1.23.3/

默认配置文件路径:
/usr/local/etc/nginx/nginx.conf

4、启动 Nginx。在终端中输入以下命令:

nginx

如果看到 “nginx: [alert] could not open error log file: open()” 这样的消息,可以创建错误日志文件:

sudo touch /usr/local/var/log/nginx/error.log

 然后重启 Nginx:

nginx -s stop
nginx

5、 测试 Nginx 是否正常工作。在浏览器中输入以下 URL:http://localhost:8080。应该能够看到一个欢迎页面,表示 Nginx 已经成功安装。

6、 如果想在系统启动时自动启动 Nginx,执行以下操作:

sudo brew services start nginx

这会将 Nginx 添加到 macOS 的 LaunchAgents 中,使其在启动时自动启动。