-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprerender.vcl
61 lines (50 loc) · 2.05 KB
/
prerender.vcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#
# NOTE: Heroku/ELB domains resolve to multiple IP addresses and Varnish
# doesn't like this. The backend host must be a single IP address, a
# hostname that resolves to a single IP address, or a dynamically-
# generated director similar to the one described here:
#
# http://blog.cloudreach.co.uk/2013/01/varnish-and-autoscaling-love-story.html
#
import std;
include "prerender_backend.vcl";
sub vcl_recv {
if (req.url ~ "_escaped_fragment_|prerender=1" ||
req.http.user-agent ~ "baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot") {
if (req.http.user-agent ~ "Prerender") {
return(pass);
}
# FIXME: Add a whitelist of files or filetypes to never prerender
set req.backend = prerender;
# When doing SSL offloading in front of Varnish, set X-Scheme header
# to "https" before passing the request to Varnish
if (req.http.X-Scheme !~ "^http(s?)") {
set req.http.X-Scheme = "http";
}
set req.url = "/" + req.http.X-Scheme + "://" + req.http.Host + req.url;
return(lookup);
}
}
sub vcl_miss {
if (req.backend == prerender) {
set bereq.http.Host = "service.prerender.io";
set bereq.http.X-Real-IP = client.ip;
set bereq.http.X-Forwarded-For = client.ip;
# If you're using hosted prerender.io, set your token here to enable
# stat collection.
#
# IMPORTANT: This information is cached for the lifespan of
# the Varnish daemon. If you change your token, you must restart Varnish.
#
# FIXME: This would ideally be handled via environment variables.
# I don't think that environment variables are available in Varnish.
# I'm looking into it.
set bereq.http.X-Prerender-Token = std.fileread("/etc/varnish/prerender_token.txt");
}
}
sub vcl_fetch {
if (req.backend == prerender) {
# Set the Varnish cache timeout for rendered content
set beresp.ttl = 60m;
}
}