Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I installed Nginx using homebrew and after completing the installation the following message was displayed:

In the interest of allowing you to run `nginx` without `sudo`, the default
port is set to localhost:8080.

If you want to host pages on your local machine to the public, you should
change that to localhost:80, and run `sudo nginx`. You'll need to turn off
any other web servers running port 80, of course.

You can start nginx automatically on login running as your user with:
  mkdir -p ~/Library/LaunchAgents
  cp #{prefix}/org.nginx.nginx.plist ~/Library/LaunchAgents/
  launchctl load -w ~/Library/LaunchAgents/org.nginx.nginx.plist

Though note that if running as your user, the launch agent will fail if you
try to use a port below 1024 (such as http's default of 80.)

But I want Nginx, on port 80, running at login and I don't want to have to open terminal and type in sudo nginx to do it. I want it to load from a plist file like Redis and PostgreSQL do.

I moved the plist to /Library/LaunchAgents/ from the user folder equivalent and changed its ownership, also tried setting the user directive in the nginx.conf file and still the same error message in

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

(along with another message telling me that since nginx was being run without super-user privileges, the user directive was being ignored)

share|improve this question
Be sure your plist file has "root:wheel" ownership when you move it in any of LaunchDaemons folders. otherwise launchctl won't run it beacuse of "dubious ownership". – risyasin Aug 20 '14 at 23:29

5 Answers 5

I had the same question and found the answer and a thorough write-up here:

share|improve this answer
How is this different than simply typing sudo nginx? – Bryson Jul 23 '11 at 8:54
The instructions still ultimately uses sudo nginx but doesn't require you to open up a terminal to do it -- it runs at login. – Brandon Jul 25 '11 at 0:02
Assuming I've disabled passwords for sudo...very well. – Bryson Jul 26 '11 at 17:21

I found an easier approach was to create add plist file in /Library/LaunchDaemons/

sudo vi /Library/LaunchDaemons/org.nginx.nginx.plist

Or, if you want it to launch on login, you can put it in ~/Library/LaunchAgents/, the same plist file. This will allow you to access the launchd launchctl command from your username without the need to call sudo.

and insert the following (be sure to update the path to your nginx install, and the username to your username):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
share|improve this answer
This is a useful answer, but technically it starts nginx at boot, not login. If @Bryson really only wants it running after he logs into a certain GUI account, then this is not quite the right answer. But I suspect he really wants it running as soon as the machine has booted, even if the GUI is waiting at Login Window, rather than waiting until he actually logs in. – Spiff Mar 12 '12 at 20:10
I added it to ~/Library/LaunchAgents/ and I get the following errors in Console: 3/30/13 9:39:24.047 AM[884]: (nginx) Unknown key for boolean: NetworkState 3/30/13 9:39:24.047 AM[884]: (nginx) Ignored this key: UserName 3/30/13 9:39:24.047 AM[884]: (nginx) Ignored this key: UserName. I changed Program string to /usr/local/Cellar/nginx/1.2.7/sbin/nginx if that matters. – hobbes3 Mar 30 '13 at 13:40
Actually I just took the original homebrew.mxcl.nginx.plist, changed UserName to root, then sudo chown root, and ran sudo launchctl load -w and it worked. – hobbes3 Mar 30 '13 at 14:14
Can I just check -- you have a .plist in ~/Library/LaunchAgents/ (so it's for one user only), but it starts as root? I've never seen that possibility mentioned in the documentation, and when I tried it on Mavericks it failed. – Pitarou Mar 12 '14 at 5:02
@hobbes3 @rich-kroll Almost a year later but KeepAlive can either be true, or set to a dict that contains NetworkState. So the example above should say <key>KeepAlive</key><dict><key>NetworkState</key><true/></dict> (note that I replaced KeepAlive's true with the dictionary containing NetworkState). Source:… – getWeberForStackExchange Jan 16 at 1:07

I got here because I was running into the same problem. My solution was similar to Rich's above, except I used the Homebrew nginx startup script:

sudo cp /usr/local/opt/nginx/homebrew.mxcl.nginx.plist /Library/LaunchDaemons/

For reference, here is what that homebrew.mxcl.nginx.plist looks like:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

I have 2 aliases added to my $HOME/.profile for making it easier to start and stop nginx.

# Nginx needs to bind to port 80 so must run as /Library/LaunchDaemon with sudo
alias start-nginx='sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.nginx.plist'
alias stop-nginx='sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.nginx.plist'

My problem was that for some reason nginx wasn't starting up properly initially. I just had to run the stop-nginx to unload it, and then re-start it again with start-nginx.

share|improve this answer
Alternative: lunchy restart nginx, see – Andrei Jan 30 '13 at 19:07

Not an exact answer to your question, but might come close enough: you can redirect port 80 to port 8080, using the packetfilter pf (tested on OS X 10.9). Add the following line to your /etc/pf.conf (it should come above the filtering rules):

rdr pass on lo0 inet proto tcp from any to any port http -> localhost port 8080

An explanation of (most of) the elements of this line can be found here.

For more information, see and, though the latter seems to describe a newer version of pf, in which the given line would be written differently.

share|improve this answer

I can think of two explanations:

  1. There are some lines like this in your .plist file:


    This tells launchd to launch nginx with the privileges of the specified user, rather than root.

    If you want nginx to bind to port 80, you should set the username in nginx's user directive, rather than in the .plist. nginx will then drop the privilege for the worker processes, although the master process will still be root.

  2. You have an nginx .plist in ~/Library/LaunchAgents/ (note the leading ~) rather than /Library/LaunchAgents.

    Note that it's possible to activate and deactivate .plists, so it's possible there are two nginx .plists on your system, but only one of them is active.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.