Advertisement
Guest User

Untitled

a guest
Oct 13th, 2023
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.34 KB | None | 0 0
  1. # Noticing changes to your VCL? The event log
  2. # (https://docs.fastly.com/en/guides/reviewing-service-activity-with-the-event-log)
  3. # in the web interface shows changes to your service's configurations and the
  4. # change log on developer.fastly.com (https://developer.fastly.com/reference/changes/vcl/)
  5. # provides info on changes to the Fastly-provided VCL itself.
  6. pragma optional_param geoip_opt_in true;
  7. pragma optional_param max_object_size 20971520;
  8. pragma optional_param smiss_max_object_size 20971520;
  9. pragma optional_param fetchless_purge_all 1;
  10. pragma optional_param chash_randomize_on_pass true;
  11. pragma optional_param default_ssl_check_cert 1;
  12. pragma optional_param max_backends 20;
  13. pragma optional_param customer_id "X";
  14. C!
  15. W!
  16. # Backends
  17. backend F_Host_1 {
  18. .between_bytes_timeout = 10s;
  19. .connect_timeout = 1s;
  20. .first_byte_timeout = 15s;
  21. .host = "X";
  22. .max_connections = 200;
  23. .port = "443";
  24. .share_key = "X";
  25. .ssl = true;
  26. .ssl_cert_hostname = "X";
  27. .ssl_sni_hostname = "X";
  28. }
  29. sub vcl_recv {
  30. #--FASTLY RECV BEGIN
  31. if (req.restarts == 0) {
  32. if (!req.http.X-Timer) {
  33. set req.http.X-Timer = "S" time.start.sec "." time.start.usec_frac;
  34. }
  35. set req.http.X-Timer = req.http.X-Timer ",VS0";
  36. }
  37. if (req.http.Fastly-Orig-Accept-Encoding) {
  38. if (req.http.Fastly-Orig-Accept-Encoding ~ "\bbr\b") {
  39. set req.http.Accept-Encoding = "br";
  40. }
  41. }
  42. declare local var.fastly_req_do_shield BOOL;
  43. set var.fastly_req_do_shield = (req.restarts == 0);
  44. # Snippet cookie : 100
  45. if (req.restarts == 0) {
  46. unset req.http.X-Orig-Cookie;
  47. if (req.http.Cookie) {
  48. set req.http.X-Orig-Cookie = req.http.Cookie;
  49. if (req.http.Cookie ~ "([sS]ession|Token)=") {
  50. set req.http.Cookie = "Token=1";
  51. } else {
  52. unset req.http.Cookie;
  53. }
  54. }
  55. }
  56. # default conditions
  57. set req.backend = F_Host_1;
  58. # end default conditions
  59. #--FASTLY RECV END
  60. if (req.request != "HEAD" && req.request != "GET" && req.request != "FASTLYPURGE") {
  61. return(pass);
  62. }
  63. return(lookup);
  64. }
  65. sub vcl_fetch {
  66. declare local var.fastly_disable_restart_on_error BOOL;
  67. #--FASTLY FETCH BEGIN
  68. # record which cache ran vcl_fetch for this object and when
  69. set beresp.http.Fastly-Debug-Path = "(F " server.identity " " now.sec ") " if(beresp.http.Fastly-Debug-Path, beresp.http.Fastly-Debug-Path, "");
  70. # generic mechanism to vary on something
  71. if (req.http.Fastly-Vary-String) {
  72. if (beresp.http.Vary) {
  73. set beresp.http.Vary = "Fastly-Vary-String, " beresp.http.Vary;
  74. } else {
  75. set beresp.http.Vary = "Fastly-Vary-String, ";
  76. }
  77. }
  78. # Snippet cache load.php : 100
  79. if (req.url ~ "^/load.php\?.*" ) {
  80. set beresp.cacheable = true;
  81. }
  82. # Snippet special : 100
  83. if (req.url ~ "^/wiki/Special:[A-Za-z]+" ) {
  84. set beresp.cacheable = false;
  85. return(pass);
  86. }
  87. # priority: 0
  88. # max-age
  89. set beresp.ttl = 86400s;
  90. # Header rewrite Cache-Control : 10
  91. set beresp.http.cache-control = "public, max-age=3600";
  92. # Header rewrite Surrogate-Control : 10
  93. set beresp.http.surrogate-control = "max-age=84000";
  94. # Gzip Generated by default compression policy
  95. if ((beresp.status == 200 || beresp.status == 404) && (beresp.http.content-type ~ "^(?:text/html|application/x-javascript|text/css|application/javascript|text/javascript|application/json|application/vnd\.ms-fontobject|application/x-font-opentype|application/x-font-truetype|application/x-font-ttf|application/xml|font/eot|font/opentype|font/otf|image/svg\+xml|image/vnd\.microsoft\.icon|text/plain|text/xml)\s*(?:$|;)" || req.url ~ "\.(?:css|js|html|eot|ico|otf|ttf|json|svg)(?:$|\?)" ) ) {
  96. # always set vary to make sure uncompressed versions dont always win
  97. if (!beresp.http.Vary ~ "Accept-Encoding") {
  98. if (beresp.http.Vary) {
  99. set beresp.http.Vary = beresp.http.Vary ", Accept-Encoding";
  100. } else {
  101. set beresp.http.Vary = "Accept-Encoding";
  102. }
  103. }
  104. if (req.http.Accept-Encoding == "br") {
  105. set beresp.brotli = true;
  106. } elsif (req.http.Accept-Encoding == "gzip") {
  107. set beresp.gzip = true;
  108. }
  109. }
  110. # priority: 10
  111. if ( req.http.Authorization || req.http.Cookie ~ "([sS]ession|Token)=" ) {
  112. # Bypass on Cookie
  113. set beresp.ttl = 0s;
  114. return(pass);
  115. }
  116. # priority: 10
  117. if ( req.url !~ "^/load\.php\?.*" ) {
  118. # cache load.php
  119. set beresp.ttl = 84000s;
  120. # Header rewrite Vary : 10
  121. set beresp.http.Vary = "Accept-Encoding, Cookie";
  122. }
  123. # priority: 10
  124. if ( req.url !~ "^/wiki/Special:[A-Za-z]+" ) {
  125. # special
  126. set beresp.ttl = 0s;
  127. return(pass);
  128. }
  129. #--FASTLY FETCH END
  130. if (!var.fastly_disable_restart_on_error) {
  131. if ((beresp.status == 500 || beresp.status == 503) && req.restarts < 1 && (req.request == "GET" || req.request == "HEAD")) {
  132. restart;
  133. }
  134. }
  135. if(req.restarts > 0 ) {
  136. set beresp.http.Fastly-Restarts = req.restarts;
  137. }
  138. if (beresp.http.Set-Cookie) {
  139. set req.http.Fastly-Cachetype = "SETCOOKIE";
  140. return (pass);
  141. }
  142. if (beresp.http.Cache-Control ~ "private") {
  143. set req.http.Fastly-Cachetype = "PRIVATE";
  144. return (pass);
  145. }
  146. if (beresp.status == 500 || beresp.status == 503) {
  147. set req.http.Fastly-Cachetype = "ERROR";
  148. set beresp.ttl = 1s;
  149. set beresp.grace = 5s;
  150. return (deliver);
  151. }
  152. if (beresp.http.Expires || beresp.http.Surrogate-Control ~ "max-age" || beresp.http.Cache-Control ~"(?:s-maxage|max-age)") {
  153. # keep the ttl here
  154. } else {
  155. # apply the default ttl
  156. set beresp.ttl = 3600s;
  157. }
  158. return(deliver);
  159. }
  160. sub vcl_hit {
  161. #--FASTLY HIT BEGIN
  162. # we cannot reach obj.ttl and obj.grace in deliver, save them when we can in vcl_hit
  163. set req.http.Fastly-Tmp-Obj-TTL = obj.ttl;
  164. set req.http.Fastly-Tmp-Obj-Grace = obj.grace;
  165. {
  166. set req.http.Fastly-Cachetype = "HIT";
  167. }
  168. #--FASTLY HIT END
  169. if (!obj.cacheable) {
  170. return(pass);
  171. }
  172. return(deliver);
  173. }
  174. sub vcl_miss {
  175. #--FASTLY MISS BEGIN
  176. # this is not a hit after all, clean up these set in vcl_hit
  177. unset req.http.Fastly-Tmp-Obj-TTL;
  178. unset req.http.Fastly-Tmp-Obj-Grace;
  179. {
  180. if (req.http.Fastly-Check-SHA1) {
  181. error 550 "Doesnt exist";
  182. }
  183. #--FASTLY BEREQ BEGIN
  184. {
  185. {
  186. if (req.http.Fastly-FF) {
  187. set bereq.http.Fastly-Client = "1";
  188. }
  189. }
  190. {
  191. # do not send this to the backend
  192. unset bereq.http.Fastly-Original-Cookie;
  193. unset bereq.http.Fastly-Original-URL;
  194. unset bereq.http.Fastly-Vary-String;
  195. unset bereq.http.X-Varnish-Client;
  196. }
  197. if (req.http.Fastly-Temp-XFF) {
  198. if (req.http.Fastly-Temp-XFF == "") {
  199. unset bereq.http.X-Forwarded-For;
  200. } else {
  201. set bereq.http.X-Forwarded-For = req.http.Fastly-Temp-XFF;
  202. }
  203. # unset bereq.http.Fastly-Temp-XFF;
  204. }
  205. }
  206. #--FASTLY BEREQ END
  207. #;
  208. set req.http.Fastly-Cachetype = "MISS";
  209. }
  210. # Snippet mis : 100
  211. if (bereq.http.X-Orig-Cookie) {
  212. set bereq.http.Cookie = bereq.http.X-Orig-Cookie;
  213. unset bereq.http.X-Orig-Cookie;
  214. }
  215. #--FASTLY MISS END
  216. return(fetch);
  217. }
  218. sub vcl_deliver {
  219. #--FASTLY DELIVER BEGIN
  220. # record the journey of the object, expose it only if req.http.Fastly-Debug.
  221. if (req.http.Fastly-Debug || req.http.Fastly-FF) {
  222. set resp.http.Fastly-Debug-Path = "(D " server.identity " " now.sec ") "
  223. if(resp.http.Fastly-Debug-Path, resp.http.Fastly-Debug-Path, "");
  224. set resp.http.Fastly-Debug-TTL = if(obj.hits > 0, "(H ", "(M ")
  225. server.identity
  226. if(req.http.Fastly-Tmp-Obj-TTL && req.http.Fastly-Tmp-Obj-Grace, " " req.http.Fastly-Tmp-Obj-TTL " " req.http.Fastly-Tmp-Obj-Grace " ", " - - ")
  227. if(resp.http.Age, resp.http.Age, "-")
  228. ") "
  229. if(resp.http.Fastly-Debug-TTL, resp.http.Fastly-Debug-TTL, "");
  230. set resp.http.Fastly-Debug-Digest = digest.hash_sha256(req.digest);
  231. } else {
  232. unset resp.http.Fastly-Debug-Path;
  233. unset resp.http.Fastly-Debug-TTL;
  234. unset resp.http.Fastly-Debug-Digest;
  235. }
  236. # add or append X-Served-By/X-Cache(-Hits)
  237. {
  238. if(!resp.http.X-Served-By) {
  239. set resp.http.X-Served-By = server.identity;
  240. } else {
  241. set resp.http.X-Served-By = resp.http.X-Served-By ", " server.identity;
  242. }
  243. set resp.http.X-Cache = if(resp.http.X-Cache, resp.http.X-Cache ", ","") if(fastly_info.state ~ "HIT(?:-|\z)", "HIT", "MISS");
  244. if(!resp.http.X-Cache-Hits) {
  245. set resp.http.X-Cache-Hits = obj.hits;
  246. } else {
  247. set resp.http.X-Cache-Hits = resp.http.X-Cache-Hits ", " obj.hits;
  248. }
  249. }
  250. if (req.http.X-Timer) {
  251. set resp.http.X-Timer = req.http.X-Timer ",VE" time.elapsed.msec;
  252. }
  253. # VARY FIXUP
  254. {
  255. # remove before sending to client
  256. set resp.http.Vary = regsub(resp.http.Vary, "Fastly-Vary-String, ", "");
  257. if (resp.http.Vary ~ "^\s*$") {
  258. unset resp.http.Vary;
  259. }
  260. }
  261. unset resp.http.X-Varnish;
  262. # Pop the surrogate headers into the request object so we can reference them later
  263. set req.http.Surrogate-Key = resp.http.Surrogate-Key;
  264. set req.http.Surrogate-Control = resp.http.Surrogate-Control;
  265. # If we are not forwarding or debugging unset the surrogate headers so they are not present in the response
  266. if (!req.http.Fastly-FF && !req.http.Fastly-Debug) {
  267. unset resp.http.Surrogate-Key;
  268. unset resp.http.Surrogate-Control;
  269. }
  270. if(resp.status == 550) {
  271. return(deliver);
  272. }
  273. #default response conditions
  274. #--FASTLY DELIVER END
  275. return(deliver);
  276. }
  277. sub vcl_error {
  278. #--FASTLY ERROR BEGIN
  279. if (obj.status == 801) {
  280. set obj.status = 301;
  281. set obj.response = "Moved Permanently";
  282. set obj.http.Location = "https://" req.http.host req.url;
  283. synthetic {""};
  284. return (deliver);
  285. }
  286. if (req.http.Fastly-Restart-On-Error) {
  287. if (obj.status == 503 && req.restarts == 0) {
  288. restart;
  289. }
  290. }
  291. {
  292. if (obj.status == 550) {
  293. return(deliver);
  294. }
  295. }
  296. #--FASTLY ERROR END
  297. }
  298. sub vcl_pipe {
  299. #--FASTLY PIPE BEGIN
  300. {
  301. #--FASTLY BEREQ BEGIN
  302. {
  303. {
  304. if (req.http.Fastly-FF) {
  305. set bereq.http.Fastly-Client = "1";
  306. }
  307. }
  308. {
  309. # do not send this to the backend
  310. unset bereq.http.Fastly-Original-Cookie;
  311. unset bereq.http.Fastly-Original-URL;
  312. unset bereq.http.Fastly-Vary-String;
  313. unset bereq.http.X-Varnish-Client;
  314. }
  315. if (req.http.Fastly-Temp-XFF) {
  316. if (req.http.Fastly-Temp-XFF == "") {
  317. unset bereq.http.X-Forwarded-For;
  318. } else {
  319. set bereq.http.X-Forwarded-For = req.http.Fastly-Temp-XFF;
  320. }
  321. # unset bereq.http.Fastly-Temp-XFF;
  322. }
  323. }
  324. #--FASTLY BEREQ END
  325. #;
  326. set req.http.Fastly-Cachetype = "PIPE";
  327. set bereq.http.connection = "close";
  328. }
  329. #--FASTLY PIPE END
  330. }
  331. sub vcl_pass {
  332. #--FASTLY PASS BEGIN
  333. {
  334. #--FASTLY BEREQ BEGIN
  335. {
  336. {
  337. if (req.http.Fastly-FF) {
  338. set bereq.http.Fastly-Client = "1";
  339. }
  340. }
  341. {
  342. # do not send this to the backend
  343. unset bereq.http.Fastly-Original-Cookie;
  344. unset bereq.http.Fastly-Original-URL;
  345. unset bereq.http.Fastly-Vary-String;
  346. unset bereq.http.X-Varnish-Client;
  347. }
  348. if (req.http.Fastly-Temp-XFF) {
  349. if (req.http.Fastly-Temp-XFF == "") {
  350. unset bereq.http.X-Forwarded-For;
  351. } else {
  352. set bereq.http.X-Forwarded-For = req.http.Fastly-Temp-XFF;
  353. }
  354. # unset bereq.http.Fastly-Temp-XFF;
  355. }
  356. }
  357. #--FASTLY BEREQ END
  358. #;
  359. set req.http.Fastly-Cachetype = "PASS";
  360. }
  361. # Snippet restore : 100
  362. if (bereq.http.X-Orig-Cookie) {
  363. set bereq.http.Cookie = bereq.http.X-Orig-Cookie;
  364. unset bereq.http.X-Orig-Cookie;
  365. }
  366. #--FASTLY PASS END
  367. }
  368. sub vcl_log {
  369. #--FASTLY LOG BEGIN
  370. # default response conditions
  371. #--FASTLY LOG END
  372. }
  373. sub vcl_hash {
  374. #--FASTLY HASH BEGIN
  375. #if unspecified fall back to normal
  376. {
  377. set req.hash += req.url;
  378. set req.hash += req.http.host;
  379. set req.hash += req.vcl.generation;
  380. return (hash);
  381. }
  382. #--FASTLY HASH END
  383. }
  384.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement