8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Macでport80でnginxを自動起動

Posted at

brewでインストールしたnginxが、ターミナルからは起動できるのに、launchctlでの自動起動がなかなか起動できなかったので、メモ。

plist

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>KeepAlive</key>
    <false/>
    <key>NetworkState</key>
    <true/>
    <key>RunAtLoad</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/nginx</string>
    </array>
    <key>Sockets</key>
    <dict>
      <key>Listeners</key>
      <dict>
        <key>SockNodeName</key>
        <string>127.0.0.1</string>
        <key>SockServiceName</key>
        <string>http</string>
      </dict>
    </dict>
  </dict>
</plist>

特に重要なのがSockets以下で、これがないと

nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)

が出ました。

ファイルの設置場所

/Library/LaunchDaemons

登録方法

sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

やってみたけどダメ、または関係ないもの

plist
<key>UserName</key>
<string>root</string>

はなくても動きました。
sudoでlaunchctlすればいいみたいです。

plistを
~/Library/LaunchDaemons
に設置して、ownerをrootにしてsudoでlaunchctlしても動きませんでした。

8
10
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?