gpt4 book ai didi

macos - Nginx 没有启动, Homebrew 软件说它是

转载 作者:行者123 更新时间:2023-12-01 07:24:31 24 4
gpt4 key购买 nike

brew services 说 nginx 已启动..

MacBook-Pro-van-Youri:Homebrew youri$ brew services start nginx
Service `nginx` already started, use `brew services restart nginx` to restart.

与launchctl相同
MacBook-Pro-van-Youri:Homebrew youri$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist 
/Users/youri/Library/LaunchAgents/homebrew.mxcl.nginx.plist: service already loaded

我的 homebrew.mxcl.nginx.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.nginx</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/nginx/bin/nginx</string>
<string>-g</string>
<string>daemon off;</string>
</array>
<key>WorkingDirectory</key>
<string>/usr/local</string>
</dict>
</plist>

brew services list 说明如下:
MacBook-Pro-van-Youri:LaunchAgents youri$ brew services list
Name Status User Plist
mariadb started youri /Users/youri/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
nginx error youri /Users/youri/Library/LaunchAgents/homebrew.mxcl.nginx.plist
php71 started youri /Users/youri/Library/LaunchAgents/homebrew.mxcl.php71.plist

语法没问题:
MacBook-Pro-van-Youri:LaunchAgents youri$ plutil -lint homebrew.mxcl.nginx.plist 
homebrew.mxcl.nginx.plist: OK

当我运行时 sudo nginx我可以访问我的网站

最佳答案

因为nginx要从80端口启动,所以需要root。当该用户登录时,LaunchAgents 以非 root 用户身份运行。LaunchDaemons在引导时以 root 用户身份加载。

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

移动 homebrew.mxcl.nginx.plist
sudo mv ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist /Library/LaunchDaemons/

从 LaunchDaemons 文件夹加载 plist
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

现在, sudo brew services list显示正在运行的 nginx 进程
Name    Status  User  Plist
nginx started root /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

运行 brew services list没有 root 会导致错误状态,因为您需要成为 root 才能读取状态。

关于macos - Nginx 没有启动, Homebrew 软件说它是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41466283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com