Skip to content

Instantly share code, notes, and snippets.

View ThijsFeryn's full-sized avatar

Thijs Feryn ThijsFeryn

View GitHub Profile
@ThijsFeryn
ThijsFeryn / EsiServiceProvider.php
Last active May 9, 2022 12:51
The various Laravel snippets I used in my Laracon EU 2022 Amsterdam presentation on how to improve the cacheability of Laravel projects. I'd like to see this end up in a larger caching or edge package and I'd like some of the code to be optimized.
<?php
//An ESI service provider that defines a custom @esi(/header) directive that can be used to render ESI tags
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Blade;
class EsiServiceProvider extends ServiceProvider
{
/**
@ThijsFeryn
ThijsFeryn / wordpress.vcl
Last active November 9, 2021 08:52
WordPress VCL
vcl 4.1;
import std;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
# Add hostnames, IP addresses and subnets that are allowed to purge content
@ThijsFeryn
ThijsFeryn / bio_en.md
Last active August 2, 2021 07:53
Thijs Feryn's bio

Thijs Feryn is a "technical evangelist" at Varnish Software, the company behind the Varnish Cache open source technology. His goal is to bring technology to the people and people to technology. He focuses on bridging the gap between code and infrastructure. Thijs is a published author with O'Reilly and with Vulkan, he is also involved in many open source communities. He speaks, listens, writes, codes, teaches, blogs, vlogs, organizes and is above all very excited to speak at "your event name"

@ThijsFeryn
ThijsFeryn / redirect.vcl
Created July 29, 2021 09:05
Redirect to the www hostname in Varnish
vcl 4.0;
import std;
sub vcl_recv {
if (!req.http.X-Forwarded-Proto) {
if(std.port(server.ip) == 443) {
set req.http.X-Forwarded-Proto = "https";
} else {
set req.http.X-Forwarded-Proto = "http";
@ThijsFeryn
ThijsFeryn / magento.vcl
Last active July 28, 2021 18:57
Magento VCL
vcl 4.0;
import std;
backend default {
.host = "localhost";
.port = "8080";
.first_byte_timeout = 600s;
.probe = {
.url = "/health_check.php";
@ThijsFeryn
ThijsFeryn / drupalcon_jwt_varnish.vcl
Created September 27, 2017 20:02
VCL file that describes my JWT implementation in Varnish for Drupal. Part of my DrupalCon Vienna 2017 presentation.
vcl 4.0;
import std;
import var;
import cookie;
import digest;
acl internal {
"192.168.20.0"/24;
}
@ThijsFeryn
ThijsFeryn / .htaccess
Created September 18, 2017 11:22
Force HTTPS redirect for sites behind a reverse (caching) proxy that terminates SSL
SetEnvIf X-Forwarded-Proto "https" HTTPS=on
Header append Vary: X-Forwarded-Proto
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
@ThijsFeryn
ThijsFeryn / default.vcl
Created June 22, 2020 13:18
Varnish synth output
vcl 4.1;
backend default none;
sub vcl_recv {
return(synth(200,"OK"));
}
@ThijsFeryn
ThijsFeryn / varnish.service
Created May 13, 2020 12:01
varnish systemd service
[Unit]
Description=Varnish Cache Plus, a high-performance HTTP accelerator
After=network-online.target
[Service]
Type=forking
KillMode=process
# Maximum number of open files (for ulimit -n)
LimitNOFILE=131072
@ThijsFeryn
ThijsFeryn / docker-compose.yml
Created April 1, 2020 11:10
Varnish docker-compose.yml file that defines container dependencies
version: '3'
services:
echo-server:
image: "jmalloc/echo-server:latest"
container_name: origin
hostname: origin
ports:
- "8080:8080"
varnish:
image: "varnish:latest"