Skip to content

Instantly share code, notes, and snippets.

@fs
Created October 3, 2008 18:52
Show Gist options
  • Save fs/14614 to your computer and use it in GitHub Desktop.
Save fs/14614 to your computer and use it in GitHub Desktop.
location / {
# serve assets with timestamp directly with max expires header
if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png)\?[0-9]+$") {
expires max;
break;
}
# If the file exists as a static file serve it directly without
# running all the other rewite tests on it
if (-f $request_filename) {
break;
}
# this rewrites all the requests to the maintenance.html
# page if it exists in the doc root. This is for capistrano's
# disable web task
if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}
# needed to forward user's IP address to rails
proxy_set_header X-Real-IP $remote_addr;
# needed for HTTPS
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header "ENABLE_X_ACCEL_REDIRECT" "true";
proxy_redirect false;
proxy_max_temp_file_size 0;
# check for index.html for directory index
# if its there on the filesystem then rewite
# the url to add /index.html to the end of it
# and then break to send it to the next config rules.
#if (-f $request_filename/index.html) {
# rewrite (.*) $1/index.html break;
#}
# this is the meat of the rails page caching config
# it adds .html to the end of the url and then checks
# the filesystem for that file. If it exists, then we
# rewite the url to have explicit .html on the end
# and then send it on its way to the next config rule.
# if there is no file on the fs then it sets all the
# necessary headers and proxies to our upstream mongrels
#if (-f $request_filename.html) {
# rewrite (.*) $1.html break;
#}
if (!-f $request_filename) {
proxy_pass http://upstream
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment