Last active
April 30, 2017 14:39
-
-
Save ivmm/243998f8fd888f28dfe2a9173447ffa8 to your computer and use it in GitHub Desktop.
default.vcl
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
# Based on:https://gist.githubusercontent.com/ivmm/243998f8fd888f28dfe2a9173447ffa8/raw/8bf3aedca049224e81779aca3621fc6d16d2c108/default.vcl | |
# 修改第 18行 的 mf8.biz 为你的域名 | |
vcl 4.0; | |
import std; | |
backend default { | |
.host = "127.0.0.1"; | |
.port = "80"; | |
} | |
acl purger { | |
"localhost"; | |
"139.59.239.92"; | |
} | |
sub vcl_recv { | |
if (client.ip != "127.0.0.1" && std.port(server.ip) == 80 && req.http.host ~ "^(?i)mf8.biz") { | |
set req.http.x-redir = "https://" + req.http.host + req.url; | |
return(synth(850, "Moved permanently")); | |
} | |
if (req.method == "PURGE") { | |
if (!client.ip ~ purger) { | |
return(synth(405, "This IP is not allowed to send PURGE requests.")); | |
} | |
return (purge); | |
} | |
if (req.restarts == 0) { | |
if (req.http.X-Forwarded-For) { | |
set req.http.X-Forwarded-For = client.ip; | |
} | |
} | |
if (req.http.Authorization || req.method == "POST") { | |
return (pass); | |
} | |
if (req.url ~ "/feed") { | |
return (pass); | |
} | |
if (req.url ~ "wp-admin|wp-login") { | |
return (pass); | |
} | |
set req.http.cookie = regsuball(req.http.cookie, "wp-settings-\d+=[^;]+(; )?", ""); | |
set req.http.cookie = regsuball(req.http.cookie, "wp-settings-time-\d+=[^;]+(; )?", ""); | |
if (req.http.cookie == "") { | |
unset req.http.cookie; | |
} | |
} | |
sub vcl_synth { | |
if (resp.status == 850) { | |
set resp.http.Location = req.http.x-redir; | |
set resp.status = 302; | |
return (deliver); | |
} | |
} | |
sub vcl_purge { | |
set req.method = "GET"; | |
set req.http.X-Purger = "Purged"; | |
return (restart); | |
} | |
sub vcl_backend_response { | |
set beresp.ttl = 24h; | |
set beresp.grace = 1h; | |
if (bereq.url !~ "wp-admin|wp-login|product|cart|checkout|my-account|/?remove_item=") { | |
unset beresp.http.set-cookie; | |
} | |
} | |
sub vcl_deliver { | |
if (req.http.X-Purger) { | |
set resp.http.X-Purger = req.http.X-Purger; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment