Skip to content

Instantly share code, notes, and snippets.

@solars
Created April 27, 2009 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solars/102574 to your computer and use it in GitHub Desktop.
Save solars/102574 to your computer and use it in GitHub Desktop.
upstream <%= application %> {
<% 0.upto(mongrel_servers - 1) do |i| %>
server 127.0.0.1:<%= mongrel_port + i %>;
<% end %>
}
server {
listen 80;
server_name <%= nginx_server_name %>;
if ($host ~* ^www.(.+)$) {
set $newhost $1;
rewrite ^/(.*)$ http://$newhost/$1 permanent;
}
access_log /var/log/<%= application %>.access.log combined;
error_log /var/log/<%= application %>.error.log debug;
root /var/apps/<%= application %>/current/public;
# Capistrano
if (-f $document_root/maintenance.html) {
rewrite ^(.*)$ /maintenance.html last;
break;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
if (-f $document_root/cache/$host$uri/index.html) {
rewrite (.*) /cache/$host$1/index.html last;
}
if (-f $document_root/cache/$host$uri.html) {
rewrite (.*) /cache/$host$1.html last;
}
if (-f $document_root/cache/$host$uri) {
rewrite (.*) /cache/$host$1 last;
}
if (!-f $request_filename) {
proxy_pass http://<%= application %>;
break;
}
}
location /admin {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://<%= application %>;
}
location ~ ^/assets/\d+/ {
rewrite ^/assets/(\d+)/(.+)$ /assets/$host/$1/$2 last;
}
location /assets {}
location /cache {}
location ~ ^/(images|javascripts|stylesheets)/mephisto {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment