Skip to content

Instantly share code, notes, and snippets.

@theAl
Forked from akiatoji/gist:3044056
Created February 2, 2016 08:36
Show Gist options
  • Save theAl/502985d01008b8354364 to your computer and use it in GitHub Desktop.
Save theAl/502985d01008b8354364 to your computer and use it in GitHub Desktop.
Nginx + Passenger 3 + RVM for Rack app on OS X using homebrew only

Most examples I found tell you to run rvmsudo or passenger-install-nginx-module. I ran into problems with these because:

  1. 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.

  2. 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:

  1. If brew install nginx --with-passenger fails with permission issues, you probably ran rvmsudo passenger-install-nginx-module before. Be sure to chown -R YOU ~/.rvm/*

  2. 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.

  3. 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 check passenger_root and passenger_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.

  4. 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 run rvm wrapper command.

  5. 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.

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