MacOS – Nginx on 10.7 with homebrew

homebrewmacoswebserver

I've purchased an "old" Mac Mini (macmini2,1) from a coworker to serve as a media server beneath my TV. It runs 10.7.5 and can't update any further, it's got a 1.83Ghz Core2Duo and 4Gb RAM, and I've stuffed a 128Gb Apple SSD in it.

I'm trying to install nginx on it to act as a small home web server, to quickly share files with colleagues and host some development I'm doing. I'm used to do this on Debian installs, but it's the first time I'm doing it on OSX and I want to do things well.

So I've installed nginx with Homebrew:

brew install nginx

and I'm trying to set it up so that:

  • it loads at boot, without the need to login (via /Library/LaunchDaemons, though I'm not proficient with that yet) – can anybody help me with the plist?
  • it runs as www-data, not root – can anybody tell me which is the best way to create this user account? It does not need to be able to login through the window manager, it's just meant to be a unix account. Though I'd appreciate being able to connect to the mini with AFP as www-data and directly share the /var/www (or equivalent) folder on my LAN, that'd help me drop files easily. Probably /usr/local/var/www from what I understand. Again, I'm accustomed to doing that with Debian (with the help of netatalk and avahi).

What's the best setup for doing this? Directory structures, configuration files?

Any pointer appreciated for the nginx.conf too, cause the stock config provided by Homebrew is quite different from what I'm used to on Debian.

Also, won't it conflict with the stock Apache? I want to run it on port 80 (and eventually make it available to the whole world).

(PHP would be welcome too, but for now I just want a solid, plain old webserver, before adding PHP to it).

[Note: I'd rather tag this question nginx, but I can't as I haven't earned enough rep here. Can somebody tag it for me?]

Best Answer

If you type brew info nginx you should get answers to many of your questions. In particular, you should see something like:

To have launchd start nginx at login:
    ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents
Then to load nginx now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

So I expect if you link the plist to /Library/LaunchDaemons instead of ~/Library/LaunchAgents it will load at boot.

I don't know what you want to change, but it's the same nginx as you use on Debian, so you can copy over your Debian nginx.conf if you want. Also the brew package comes with a set of default/example configuration files installed under /usr/local/etc/nginx/.

The default conf runs on port 8080, so you have to edit it to run on port 80, and yes it will conflict with Apache running on port 80 so you have to turn Apache off or put it on another port. Apache config files are in /private/etc/apache2/ and you can turn it off via System Preferences -> Sharing -> Personal Web Sharing. (Note that this option has been removed in Mountain Lion. Mountain Lion still ships with Apache, but it is disabled by default.)

You can, of course, set it up however you want, but if you're looking for what's easy and Mac-like, just follow the Apache setup, which uses user and group _www and uses /Library/WebServer/Documents as document root and serves user content out of ~user/Sites.