Skip to content

Instantly share code, notes, and snippets.

@jpinnix
Created August 24, 2010 17:55
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jpinnix/547977 to your computer and use it in GitHub Desktop.
Save jpinnix/547977 to your computer and use it in GitHub Desktop.
Help nginx+passenger serve static index pages
# Help nginx+passenger serve static index pages
# Site specific config
server {
listen 80;
server_name domain.com;
index index.html;
access_log logs/appname.access.log;
error_log logs/appname.error.log;
# Check for index pages first
location / {
root /home/username/appname/current/public;
try_files $uri /$uri/index.html @passenger;
}
# Okay, there isn't a static index file, so go to passenger
location @passenger {
root /home/username/appname/current/public;
proxy_set_header X-Forwarded-Proto http;
passenger_enabled on;
}
}
# nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
passenger_root /usr/local/ruby-enterprise-1.8.7-2010.02/lib/ruby/gems/1.8/gems/passenger-2.2.15;
passenger_ruby /usr/local/ruby-enterprise-1.8.7-2010.02/bin/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
fastcgi_intercept_errors on;
server {
server_name _;
return 444;
}
include /usr/local/nginx/conf/sites-enabled/*;
}
@jpinnix
Copy link
Author

jpinnix commented Aug 24, 2010

With Apache+Passenger, the serving of index pages "just works". This definitely required a lot of digging and almost no one had any ideas. Finally on #linode IRC, someone suggested using try_files and there was an example on ServerFault (http://j.mp/cYHGQh) of how to accomplish this for cached pages. But I was just wanting it to work for static pages.

@ippa
Copy link

ippa commented Aug 30, 2011

Thanks a bunch for this. I just switched from apache -> nginx and this was just what I needed!

@stepheneb
Copy link

I have a pull request here that fixes this in passenger: phusion/passenger#15

Unfortunately it's been ignored -- haven't been able to even get any feedback about why it isn't accepted.

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