macOS 升级到 14.0 Sonoma 之后 nginx 无法启动问题
macOS 升级到 14.0 Sonoma 之后,发现 brew 安装的 nginx 无法启动了。
sudo brew services list
查看状态:
nginx error 256 root /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
手动启动之:
$ sudo brew services start nginx
Warning: Taking root:admin ownership of some nginx paths:
/opt/homebrew/Cellar/nginx/1.25.2/bin
/opt/homebrew/Cellar/nginx/1.25.2/bin/nginx
/opt/homebrew/opt/nginx
/opt/homebrew/opt/nginx/bin
/opt/homebrew/var/homebrew/linked/nginx
This will require manual removal of these paths using `sudo rm` on
brew upgrade/reinstall/uninstall.
Warning: nginx must be run as non-root to start at user login!
Bootstrap failed: 5: Input/output error
Error: Failure while executing; `/bin/launchctl bootstrap system /Library/LaunchDaemons/homebrew.mxcl.nginx.plist` exited with 5.
Warning
可以忽略(因为我本地跑在 80 端口,必须使用 root 权限)。
造成无法启动的原因是下面的错误:
Bootstrap failed: 5: Input/output error
Error: Failure while executing; `/bin/launchctl bootstrap system /Library/LaunchDaemons/homebrew.mxcl.nginx.plist` exited with 5.
解决方案
首先使用 sudo nginx -t
命令检查 nginx 配置是否正常。我的错误主要就是因为升级后 /var/log/nginx
目录被删除了导致的。我之前配置了一个日志输出目录在 /var/log/nginx/xxx_error.log
,升级后这个整个目录不见了,导致无法启动。
其次,要先执行 sudo brew services stop nginx
,然后再使用 sudo brew services start nginx
启动。
如果还不行,可以给我发邮件咨询,请附上你的详细错误信息。