-
-
Save nigareps/b9348e7ec26a6fb5e1d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a basic VCL configuration file for varnish. See the vcl(7) | |
# man page for details on VCL syntax and semantics. | |
# | |
# Default backend definition. Set this to point to your content | |
# server. | |
# | |
backend default { | |
.host = "127.0.0.1"; | |
.port = "8081"; | |
} | |
# Respond to incoming requests. | |
sub vcl_recv { | |
# set right IP address | |
remove req.http.X-Forwarded-For; | |
set req.http.X-Forwarded-For = client.ip; | |
# Allow the backend to serve up stale content if it is responding slowly. | |
set req.grace = 6h; | |
# Do not cache these paths. | |
if (req.url ~ "^/status\.php$" || | |
req.url ~ "^/update\.php$" || | |
req.url ~ "^/user$" || | |
req.url ~ "^/myadmin108" || | |
req.url ~ "^/admin$" || | |
req.url ~ "^/auth_test/.*$" || | |
req.url ~ "^/auth_test$" || | |
req.url ~ "^/intranet_login/.*$" || | |
req.url ~ "^/intranet_login$" || | |
req.url ~ "^/admin/.*$" || | |
req.url ~ "^/user/.*$" || | |
req.url ~ "^/flag/.*$" || | |
req.url ~ "^.*/ajax/.*$" || | |
req.url ~ "^.*/ahah/.*$") { | |
return (pass); | |
} | |
# Always cache the following file types for all users. This list of extensions | |
# appears twice, once here and again in vcl_fetch so make sure you edit both | |
# and keep them equal. | |
if (req.url ~ "(?i)\.(pdf|asc|dat|txt|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|css|js)(\?.*)?$") { | |
unset req.http.Cookie; | |
} | |
if (req.http.Cookie) { | |
if (req.http.Cookie ~ "AUTH") { | |
return (pass); | |
} | |
else { | |
if(req.request != "POST") { | |
unset req.http.Cookie; | |
return (lookup); | |
} else { | |
return (pass); | |
} | |
} | |
} else { | |
return (lookup); | |
} | |
} | |
# Set a header to track a cache HIT/MISS. | |
sub vcl_deliver { | |
if (obj.hits > 0) { | |
set resp.http.X-Varnish-Cache = "HIT"; | |
} | |
else { | |
set resp.http.X-Varnish-Cache = "MISS"; | |
} | |
} | |
# Code determining what to do when serving items from the Apache servers. | |
# beresp == Back-end response from the web server. | |
sub vcl_fetch { | |
# We need this to cache 404s, 301s, 500s. Otherwise, depending on backend but | |
# definitely in Drupal's case these responses are not cacheable by default. | |
if (beresp.status == 404 || beresp.status == 301 || beresp.status == 500) { | |
set beresp.ttl = 10m; | |
} | |
# Don't allow static files to set cookies. | |
# (?i) denotes case insensitive in PCRE (perl compatible regular expressions). | |
# This list of extensions appears twice, once here and again in vcl_recv so | |
# make sure you edit both and keep them equal. | |
if (req.url ~ "(?i)\.(pdf|asc|dat|txt|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|css|js)(\?.*)?$") { | |
unset beresp.http.set-cookie; | |
} | |
# Allow items to be stale if needed. | |
set beresp.grace = 6h; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment