IMXYLZ

Mac Os下开机启动apache、nginx

| Comments

Apache 启动配置

建立一个配置文件

adylab:~ adyliu$ cat /System/Library/LaunchDaemons/org.apache.httpd.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.apache.httpd</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/sbin/apachectl</string>
        <string>-k</string>
        <string>start</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

load启动配置

adylab:~ adyliu$ sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

在mac os 10.8上需要加上-w参数,否则无法启动

下次开机就可以自动启动了,这里先手动启动。

手动启动

adylab:~ adyliu$ sudo launchctl start org.apache.httpd

查看启动

adylab:~ adyliu$ sudo launchctl list|grep httpd
12769   -   0x7fec05840410.anonymous.httpd
12768   -   0x7fec03ca9e70.anonymous.httpd
-   0   org.apache.httpd

卸载启动配置

adylab:~ adyliu$ sudo launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist

如果不再使用了,卸载配置即可。

nginx启动配置

nginx操作类似,不再重复,建立配置文件如下:

adylab:LaunchDaemons adyliu$ cat org.nginx.nginx.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.nginx.nginx</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/bin/nginx</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

Comments

回顶部