mac os x下nginx开机自启动

时间:2021-05-15 16:55:23

来自:http://hushicai.com/2013/09/21/mac-os-x-xia-nginx-kai-ji-zi-qi-dong.html

按照apple developer官网所说的,用户的开机自启动任务一般都需要在以下目录建立一个plist文件:

/Library/LaunchDaemons/
/Library/LaunchAgents/
~/Library/LaunchAgents/
我们在 /Library/LaunchDaemons 下新建一个 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>nginx</string>

<key>Program</key>
<string>/usr/local/nginx/sbin/nginx</string>

<key>KeepAlive</key>
<true/>

<key>NetworkState</key>
<true/>

<key>LaunchOnlyOnce</key>
<true/>
</dict>
</plist>
加载:

launchctl load /Library/LaunchDaemons/nginx.plist
成功!