Passenger with nginx on Mac OS X (2nd edition)
by Trevor Turk
This is a fancy new guide for setting up nginx with Passenger support on Mac OS X. You can refer to the first edition here if you like.
Let’s begin.
- Install Ruby Version Manager (optional)
- Install Homebrew
- Install Passenger
gem install passenger
- Install nginx with Passenger support
brew install nginx --with-passenger
- Follow the instructions (Caveats) that Homebrew prints out
- Open your nginx conf file
mate /usr/local/etc/nginx/nginx.conf
- Replace the contents of the file with this:
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; passenger_root /Users/trevorturk/.rvm/gems/ruby-1.8.7-p302/gems/passenger-2.2.15; passenger_ruby /Users/trevorturk/.rvm/rubies/ruby-1.8.7-p302/bin/ruby; server { listen 8080; server_name eldorado.local; root /Users/trevorturk/Code/eldorado/public; passenger_enabled on; rack_env development; } } - …then replace the passenger_root config option with your passenger root directory
passenger-config --root
- …then replace the passenger_ruby with your ruby location
which ruby
- …then replace and/or create new server blocks as necessary for your apps
- Restart nginx
kill -HUP `cat /usr/local/var/run/nginx.pid`
- Add your apps to your hosts file
mate /etc/hosts
For example…
127.0.0.1 eldorado.local
- Visit one of your apps to make sure it’s working:
open http://kzak.local:8080
fin
Note that I’m not sure how to get nginx running on port 80, and I’m not bothered enough to figure it out at the moment. Please leave a helpful comment for others if you take the time, though!
Advertisement
Port numbers lower than 1024 must be run by the root user. Given that the Homebrew normally installs all its packages under the user's home directory, and executes as that user, you wont be able to have your site on port 80.
So to get nginx to bind to port 80, you'll wanna put the plist file into the /Library/LaunchDaemons directory. (Also, make sure it doesn't specify any user account to run as, so that I just runs as root.)
I tried placing org.nginx.plist in /Library/LaunchDaemons but I still get "[emerg]: bind() to 0.0.0.0:80 failed (13: Permission denied)".
You need to start nginx with sudo or as root if you want it to run on port 80
[...] Passenger with nginx on Mac OS X (2nd edition) (tags: ruby rails nginx rvm passenger sysadmin mac) [...]
[...] Why we can’t use 80 port with nginx installed by brew. http://trevorturk.com/2010/09/22/passenger-with-nginx-on-mac-os-x-2nd-edition-2/ [...]