Skip to content

Instantly share code, notes, and snippets.

@isaac
Created December 16, 2008 00:20
Show Gist options
  • Save isaac/36188 to your computer and use it in GitHub Desktop.
Save isaac/36188 to your computer and use it in GitHub Desktop.
upstream mephisto {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
server 127.0.0.1:8003;
}
server {
listen 80;
server_name example.com;
root /var/www/apps/mephisto/current/public;
access_log /var/www/apps/mephisto/shared/log/example.com-access.log;
error_log /var/www/apps/mephisto/shared/log/example.com-error.log;
client_max_body_size 50M;
set $port "";
if ($server_port != 80) {
set $port :$server_port;
}
if ($host ~* ^www\.(.*)$) {
set $domain $1;
rewrite ^(.+)$ $scheme://$domain$port$1 permanent;
}
if ($host ~* ^(?!www)[\w_-]+(\.[\w]+)+$) {
set $domain $host;
}
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 off;
if (-f $document_root/cache/$domain$uri/index.html) {
rewrite (.*) /cache/$domain$1index.html break;
}
if (-f $document_root/cache/$domain$uri.html) {
rewrite (.*) /cache/$domain$1.html break;
}
if (-f $document_root/cache/$domain$uri) {
rewrite (.*) /cache/$domain$1 break;
}
proxy_pass http://mephisto;
}
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://mephisto;
}
location ~ ^/assets/\d+/ {
rewrite ^/assets/(\d+)/(.+)$ /assets/$domain/$1/$2 last;
}
location /assets {}
location /cache {}
location ~ ^/(images|javascripts|stylesheets)/(mephisto) {}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment