Most examples I found tell you to run rvmsudo or passenger-install-nginx-module. I ran into problems with these because:
-
rvmsudo leaves root owned directories and files under rvm passenger gem directory. This will give you seemingly odd errors later when you try to remove/upgrade passenger gem, or try to use homebrew to install passenger.
-
There's no good place to put nginx using passenger-install-nginx-module. Putting it under /usr/local means you have to remember it's there amongst homebrew files. Anywhere else, you still have to remember you put it there. We'd rather manage nginx install via homebrew.
So to install everything with homebrew, this is what it took:
gem install passenger
brew install nginx --with-passenger
rvm wrapper ruby-1.9.2-p290 passenger
cd ~/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.13/
rake nginx
Then in your nginx config file, set passenger_root and passenger_ruby like so:
passenger_root /Users/aki/.rvm/gems/ruby-1.9.2-p290/gems/passenger-3.0.13;
passenger_ruby /Users/aki/.rvm/bin/passenger_ruby;
Issues I ran into:
-
If
brew install nginx --with-passenger
fails with permission issues, you probably ranrvmsudo passenger-install-nginx-module
before. Be sure tochown -R YOU ~/.rvm/*
-
If you keep getting 403, you likely set wrong rack/rails app root directory in nginx config. The root directory needs to point to
public
subdirectory in your app. Yes, it's unintuitive, but this is just how it is. -
If you are pointing to
public
directory correctly but still get 403, go look at nginx errorlog. It'll likely say directory listing is not allowed. This means passenger isn't being invoked. You need to checkpassenger_root
andpassenger_ruby
entries. You don't get any indication if the path is wrong or directory/binary have wrong permission, so you have to eyeball it closely. -
If you access your app via browser and get that buttugly purple error page saying it can't find things like
rack
, this is because ruby's runtime environment isn't setup right and it's unable to find gems or libraries. This happens if you run rvm installed ruby directly from nginx. To run nginx with rvm, you can't invoke ruby directly. Instead, you need to invoke wrapper (passenger_ruby
) that sets up the RVM environment. This wrapper is generated under ~/.rvm/bin when you runrvm wrapper
command. -
You need to run ```rake nginx`` in passenger gem directory or you will get an error in nginx errors.log saying that it can't find PassengerLoggingAgent.
Nowadays (starting from version 4.0.5), Phusion Passenger is available on Homebrew as well. Just run:
The last step will tell you how to activate Phusion Passenger in Nginx.
That's it! No other steps are necessary.