- clone this repo and
cdinto the directory terraform initcp terraform.tfvars.example terraform.tfvars- edit
terraform.tfvarsto populate your fastly api key and gcp project values terraform apply
- copy/paste the curl command from the terraform output, notice the lack of a cache-control header
- copy/paste the ssh command to ssh into the vm
sudo tail -f /var/log/nginx/access.log, notice your curl request is already there- click the link (or copy/paste the url) to open it in a browser tab, notice back in the terminal the request came from a new (fastly) ip
- refresh a few times, notice the requests don't hit nginx
- inspect a request in chrome, notice the HITs and age header climbing up
- ^C the log tail
sudo vi /etc/nginx/sites-available/default- look for the
locationsection already in there and copy/paste the below snippet after it
location ~ \.html$ {
add_header Cache-Control "max-age=10";
}
- restart nginx with
service nginx restart exitthe vm- re-run your curl of the direct ip, notice there is now a
cache-controlheader with a value ofmax-age=10 - refresh your browser tab, notice its still a HIT with an Age well over 10 seconds
- purge the url like so:
curl -X PURGE http://x.x.x.x
- refresh in your browser again, notice its a MISS and has the
cache-controlheader - refresh again, notice it becomes HITS and the
ageincreases - wait 10 seconds
- refresh again, notice it was a MISS again
- refresh a bunch more, notice that its mostly HITs, and that age climbs up, but doesn't go over 10
- uncomment line 23 - 35 and 52 - 55 in main.tf
terraform apply- ssh into the vm
ssh [email protected]
sudo tee -a /etc/rsyslog.d/fastly.conf <<EOF > /dev/null
module(load="imtcp")
input(type="imtcp" port="514")
local0.info /var/log/fastly
EOF
sudo service rsyslog restart
sudo tail -f /var/log/fastly
- uncommment line 49 in main.tf
terraform apply