Mac M1 Brew配置nginx開機自啟動,解決nginx自啟動不成功問題


nginx需要root身份

將啟動文件拷貝進去

sudo cp /opt/homebrew/Cellar/nginx/1.21.0/homebrew.mxcl.nginx.plist /Library/LaunchDaemons

設置開啟啟動

sudo lauchctl load -w /Library/LaunchDaemons/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>/opt/homebrew/opt/nginx/bin/nginx</string>
        <string>-g</string>
        <string>daemon off;</string>
    </array>
    <key>WorkingDirectory</key>
    <string>/opt/homebrew</string>
  </dict>
</plist>

此時並沒有生效

 % sudo brew services list
Name      Status  User   Plist
mysql@5.7 unknown jiqing /Users/jiqing/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist
nginx     error   root   /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php@5.6   unknown jiqing /Users/jiqing/Library/LaunchAgents/homebrew.mxcl.php@5.6.plist
php@7.4   stopped     

重啟之后

% sudo brew services list
Password:
Name      Status  User   Plist
mysql@5.7 unknown jiqing /Users/jiqing/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist
nginx     started root   /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php@5.6   unknown jiqing /Users/jiqing/Library/LaunchAgents/homebrew.mxcl.php@5.6.plist
php@7.4   stopped    

生效了。

下次啟動,停止記得帶上sudo。

% sudo brew services stop nginx
% sudo brew services start nginx
% brew services list
Name      Status  User   Plist
mysql@5.7 started jiqing /Users/jiqing/Library/LaunchAgents/homebrew.mxcl.mysql@5.7.plist
nginx     unknown root   /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php@5.6   started jiqing /Users/jiqing/Library/LaunchAgents/homebrew.mxcl.php@5.6.plist
php@7.4   stopped  

不加sudo的兩個服務。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM