Skip to content

Instantly share code, notes, and snippets.

@arbales
Created November 15, 2010 19:04
Show Gist options
  • Select an option

  • Save arbales/700787 to your computer and use it in GitHub Desktop.

Select an option

Save arbales/700787 to your computer and use it in GitHub Desktop.
backend default {
.host = "localhost";
.port = "8000";
}
sub vcl_recv {
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For = req.http.X-Forwarded-For ", " client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
if (req.url ~ "\.(jpe?g|png|gif|ico|js|css)(\?.*|)$") {
unset req.http.cookie;
}
if (req.url ~ "\.(jpg|jpeg|gif|png|css|js)$") {
unset req.http.cookie;
return (lookup);
}
if (req.request == "PURGE") {
purge("req.url ~ " req.url " && req.http.host == " req.http.host);
error 200 "Purged.";
}
}
sub vcl_fetch {
if (req.url ~ "\.(jpe?g|png|gif|ico|js|css)(\?.*|)$") {
unset beresp.http.set-cookie;
}
if (!beresp.cacheable) {
return (pass);
}
if (beresp.http.Set-Cookie) {
return (pass);
}
return (deliver);
}
varnishd -a 0.0.0.0:80 -f /etc/varnish/default.vcl -P /etc/varnish/varnish.pid
# 417east.com runs really fast with a Unicorn backend.
upstream east_site {
server unix:/var/WebServer/417east/tmp/sockets/unicorn.sock fail_timeout=00;
}
# 417east.com listens on port 8000, behind Varnish
server {
listen 8000 default;
server_name 417east.com www.417east.com;
access_log /var/log/nginx/417east.access.log;
error_log /var/log/nginx/417east.error.log;
root /var/WebServer/417east/public;
error_page 404 500 502 503 504 /500.html;
## Images and static content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml|html)$ {
access_log off;
expires 30d;
#root /home/
}
location = /favicon.ico {
access_log off;
log_not_found off;
}
## Disable viewing .htaccess & .htpassword
location ~ /\.ht {
deny all;
}
#unicorn
location / {
if (-f $request_filename) {
access_log off;
rewrite_log off;
expires 30d;
break;
}
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
if (!-f $request_filename) {
# my_web_app needs to be the same as whatever upstream name you assigned above
proxy_pass http://east_site;
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment