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的两个服务。

posted @ 2021-06-07 01:04  TBHacker  阅读(2281)  评论(0编辑  收藏  举报