Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- backend default {
- .host = "192.168.1.100";
- .port = "80";
- }
- acl typo3_purge {
- "localhost";
- "192.168.1.101";
- }
- sub vcl_recv {
- # Set backend
- set req.backend = default;
- // Banning
- if (req.request == "BAN") {
- if ( ! client.ip ~ typo3_purge) {
- error 405 "Not allowed.";
- }
- if ( ! req.http.Ban-Expression) {
- error 400 "Ban-Expression missing.";
- }
- ban("" + req.http.Ban-Expression);
- # Throw a synthetic page so the request wont go to the backend.
- error 200 "Ban added";
- }
- // Purging
- if (req.request == "PURGE") {
- if ( ! client.ip ~ typo3_purge) {
- error 405 "Not allowed.";
- }
- // Remove the port from the host name
- set req.http.host = regsub(req.http.host, "([^:]+).*", "\1");
- return (lookup);
- }
- # Set a unique cache header with client ip
- 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;
- }
- # Always allow post request to be sent to the backend but not cached
- if (req.request == "POST") {
- ban("req.url == " + req.url);
- set req.http.X-Test = req.url;
- return (pass);
- }
- if (req.request != "GET" &&
- req.request != "HEAD" &&
- req.request != "PUT" &&
- req.request != "POST" &&
- req.request != "TRACE" &&
- req.request != "OPTIONS" &&
- req.request != "DELETE") {
- # Pass to backend until it's closed
- return (pipe);
- }
- # If neither get nor post request, send to backend but not cached
- if (req.request != "GET" && req.request != "HEAD") {
- return (pass);
- }
- # If any autorisation was set do not cache
- if (req.http.Authorization || req.http.Cookie ~ "fe_typo_user") {
- return (pass);
- }
- # If we work in backend
- if (req.http.Cookie ~ "be_typo_user") {
- # Delete cache depending on TYPO3 cache control
- if (req.http.Cache-Control ~ "no-cache") {
- set req.ttl = 0s;
- ban("req.url == " + req.url);
- }
- return (pass);
- }
- else {
- # Delete cookie
- unset req.http.Cookie;
- }
- # Lookup in cache
- return (lookup);
- }
- sub vcl_fetch {
- # Set default cache to 12 hours
- set beresp.ttl = 12h;
- # Deliver old content up to 1 day
- set req.grace = 24h;
- # Set cache for 2 days
- if (req.url ~ "\.(jpeg|jpg|png|gif|ico|swf|js|css|txt|gz|zip|rar|bz2|tgz|tbz|html|htm|pdf|pls|torrent)$") {
- set beresp.ttl = 48h;
- }
- # Delete cookie
- if (req.url ~ "^/typo3") {
- }
- else {
- if (req.request == "POST") {
- }
- else {
- unset beresp.http.Set-Cookie;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement