Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vcl 4.0;
- # Default backend definition. Set this to point to your content server.
- backend api {
- .host = "api-nginx";
- .port = "8086";
- }
- //backend client {
- // .host = "node-client";
- // .port = "3000";
- //}
- # list IPs allowed to purge/ban
- acl invalidators {
- "localhost";
- // "varnish";
- "php";
- "127.0.0.1";
- }
- # before checking if the cache exists
- sub vcl_recv {
- // if (req.http.Host ~ "client.localhost") {
- // set req.backend_hint = client;
- // } else {
- // set req.backend_hint = api;
- // }
- if (req.url ~ "^/admin/.*" || req.url ~ "^/build/.*" || req.url ~ "(\?|&)cache=false\b") {
- return (pass);
- }
- if (req.method == "BAN") {
- if (client.ip !~ invalidators) {
- return (synth(405, "Not allowed"));
- }
- if (req.http.ApiPlatform-Ban-Regex) {
- ban("obj.http.Cache-Tags ~ " + req.http.ApiPlatform-Ban-Regex);
- return (synth(200, "Ban added"));
- }
- return (synth(400, "ApiPlatform-Ban-Regex HTTP header must be set."));
- }
- if (req.method == "PRI") {
- /* This will never happen in properly formed traffic (see: RFC7540) */
- return (synth(405));
- }
- if (!req.http.host &&
- req.esi_level == 0 &&
- req.proto ~ "^(?i)HTTP/1.1") {
- /* In HTTP/1.1, Host is required. */
- return (synth(400));
- }
- if (req.method != "GET" &&
- req.method != "HEAD" &&
- req.method != "PUT" &&
- req.method != "POST" &&
- req.method != "TRACE" &&
- req.method != "OPTIONS" &&
- req.method != "DELETE" &&
- req.method != "PATCH") {
- /* Non-RFC2616 or CONNECT which is weird. */
- return (pipe);
- }
- if (req.method != "GET" && req.method != "HEAD") {
- /* We only deal with GET and HEAD by default */
- return (pass);
- }
- unset req.http.forwarded;
- if (
- req.url ~ "(\?|&)cache=true\b" ||
- req.url ~ "^\/api\/activities" ||
- req.url ~ "^\/api\/activity_types" ||
- req.url ~ "^\/api\/attributes(?!\/revisions)" ||
- req.url ~ "^\/api\/awards" ||
- req.url ~ "^\/api\/comments\/get_by_point_of_interest" ||
- req.url ~ "^\/api\/comments\/last_community" ||
- req.url ~ "^\/api\/configs" ||
- req.url ~ "^\/api\/currency_types" ||
- req.url ~ "^\/api\/destinations" ||
- req.url ~ "^\/api\/detail_person_views" ||
- req.url ~ "^\/api\/directory_countries" ||
- req.url ~ "^\/api\/directory_departments" ||
- req.url ~ "^\/api\/elastic_activities" ||
- req.url ~ "^\/api\/known_types.*" ||
- req.url ~ "^\/api\/locales" ||
- req.url ~ "^\/api\/main_revisions" ||
- req.url ~ "^\/api\/media.*" ||
- req.url ~ "^\/api\/metadata\/seo" ||
- req.url ~ "^\/api\/partners.*" ||
- req.url ~ "^\/api\/payment_types" ||
- req.url ~ "^\/api\/people\/[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}\/rank" ||
- req.url ~ "^\/api\/person_stat_views\/[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}" ||
- req.url ~ "^\/api\/pictures(?!\/)" ||
- req.url ~ "^\/api\/point_of_interest_comments" ||
- req.url ~ "^\/api\/point_of_interest_types" ||
- req.url ~ "^\/api\/point_of_interests\/[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}\/comments" ||
- req.url ~ "^\/api\/point_of_interests\/[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}\/count_comments" ||
- req.url ~ "^\/api\/point_of_interests\/[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}\/main_revision" ||
- req.url ~ "^\/api\/press.*" ||
- req.url ~ "^\/api\/revisions(?!\/main_with_pictures).*" ||
- req.url ~ "^\/api\/team_members.*" ||
- req.url ~ "^\/api\/translations\/.*" ||
- req.url ~ "^\/api\/trip_categories" ||
- req.url ~ "^\/api\/trip_countries" ||
- req.url ~ "^\/api\/trips(?!\/)"
- ) {
- unset req.http.Cookie;
- unset req.http.Authorization;
- } else {
- return (pass);
- }
- }
- sub vcl_hash {
- if(req.http.accept-language) {
- hash_data(req.url + ";__lang__=" + req.http.accept-language);
- } else {
- hash_data(req.url + ";__lang__=" + "fr");
- }
- return (lookup);
- }
- # after reading the res headers from the back
- sub vcl_backend_response {
- if (bereq.uncacheable) {
- return (deliver);
- }
- if (beresp.status == 200 || beresp.status == 201) {
- set beresp.ttl = 1d;
- }
- set beresp.http.url = bereq.url;
- }
- # before sending res to client
- sub vcl_deliver {
- # Don't send cache tags related headers to the client
- unset resp.http.url;
- # Comment the following line to send the "Cache-Tags" header to the client (e.g. to use CloudFlare cache tags)
- unset resp.http.Cache-Tags;
- unset resp.http.X-Powered-By;
- unset resp.http.Server;
- }
Advertisement
Add Comment
Please, Sign In to add comment