Playing with nginx + passenger for Ubuntu Server/ Mac OSX

前往 檢視

(for osx yosemite ,install brew before install nginx+passenger)

After install nginx+passenger , you will see this in command line

Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that

nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To activate Phusion Passenger, add this to /usr/local/etc/nginx/nginx.conf, inside the ‘http’ context:

  passenger_root /usr/local/opt/passenger/libexec/lib/phusion_passenger/locations.ini;

  passenger_ruby /usr/bin/ruby;

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

Or, if you don’t want/need launchctl, you can just run:


1)sudo nginx  //start service , see localhost:8080 or localhost:80 will show “welcome to nginx
2) edit the /opt/nginx/conf/nginx.conf



listen 80;


root /home/www/rails_project/public #point to your rail project public folder’s location

passenger_enabled on; #for rails project

passenger_app_env development; #it your project still in development setting


//if you need more domain name in localhost…

Edit your /etc/hosts file and add the following line:; You should be able to access your apps by browsing to

(if using yosemite , flush dns cache)

forbbiden 403

try add index.html (with “<html>hello world</html>")in public folder, if web browser can access, it means you write a wrong root in nginx.conf