nginx 安裝 通過brew
$:brew install nginx
launchd
關(guān)于launchd的描述,這里引用一下manpage秸脱,如下:
launchd manages processes, both for the system as a whole and for individual users.
The primary and preferred interface to launchd is via the launchctl(1) tool which (among other options) allows the user or administrator to load and unload jobs.
Where possible, it is preferable for jobs to launch on demand based on criteria specified in their respective configuration files.
launchd also manages XPC services that are bundled within applications and frameworks on the system.
During boot launchd is invoked by the kernel to run as the first process on the system and to further bootstrap the rest of the system.
You cannot invoke launchd directly.
launchd用于為系統(tǒng)和用戶管理進程落包,主要通過launchctl對其進行操作,用戶無法直接調(diào)用launchd摊唇。
啟動時由內(nèi)核調(diào)用launchd咐蝇,運行第一個進程。
plist
另外我們需要了解的就是plist文件巷查。
plist就是property list format的意思有序,是蘋果用來保存應(yīng)用數(shù)據(jù)的格式,其實就是個xml岛请。
可以在 /usr/local/opt/nginx 下找到nginx對應(yīng)的plist文件旭寿,比如在我的電腦上是 homebrew.mxcl.nginx.plist 。
它的內(nèi)容大概是這樣:
<p><code>
<?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>
</code></p>
我們需要把這個文件復(fù)制到 /Library/LaunchDaemons 下崇败,如果是 ~/Library/LaunchAgents 也可以盅称,但兩者有區(qū)別。
前者是系統(tǒng)啟動時啟動后室,后者則是在用戶登錄時啟動缩膝。 接著執(zhí)行l(wèi)aunchctl load -w,如下:
sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
最后岸霹,重啟你的機器疾层,你會發(fā)現(xiàn)nginx在80端口啟動了。