Skip to content

Instantly share code, notes, and snippets.

@cmbankester
Last active April 29, 2022 14:08
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save cmbankester/a3517bd398475a9e3a48 to your computer and use it in GitHub Desktop.
Save cmbankester/a3517bd398475a9e3a48 to your computer and use it in GitHub Desktop.
NGINX startup on Mac OSX El Capitan
<?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>
<true/>
<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>

Install NGINX if it's not yet installed

brew install nginx

Add NGINX launcher to system launch daemons, runnable as root

sudo cp -v /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

Make sure launcher is set to keep nginx alive (see the example plist)

sudo vim /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
# Ensure this is in the file:
# <key>KeepAlive</key>
# <true/>

Launch NGINX

sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
@jiakechong1991
Copy link

good!

@mqliutie
Copy link

good job!

# Ensure this is in the file:
# <key>KeepAlive</key>
# <true/> 

That is very important

@mytharcher
Copy link

Thanks!

And the file should be copied, not only make a symbol link will work.

@morri5
Copy link

morri5 commented Dec 9, 2019

For me worked with KeepAlive false. On Catalina 10.15.1

@hacfi
Copy link

hacfi commented Aug 14, 2020

Instead of manually editing it you can update KeepAlive via:

sudo defaults write /Library/LaunchDaemons/homebrew.mxcl.nginx.plist KeepAlive -bool TRUE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment