1、安装
brew install nginx
2、修改配置文件
sudo vi /usr/local/etc/nginx/nginx.conf修改默认的8080端口为80修改日志文件地方 error_log logs/error.log; pid logs/nginx.pid; access_log logs/access.log;按上面修改后日志文件在/usr/local/opt/nginx/logs
3、修改管理员权限
sudo chown root:wheel/usr/local/opt/nginx/bin/nginxsudo chmod u+s/usr/local/opt/nginx/bin/nginx
4、加上launchctl控制
mkdir -p ~/Library/LaunchAgentscp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist ~/Library/LaunchAgents/launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
5、启动nginx
sudo nginx #启动sudo nginx -t #测试配置文件是否有错sudo nginx -s reload #重启nginx
6、问题
如果出现nginx: [error] invalid PID number "" in "/usr/local/var/run/nginx/nginx.pid",则需要 sudo nginx -c /usr/local/etc/nginx/nginx.conf sudo nginx -s reload