Skip to content

Instantly share code, notes, and snippets.

View razvanphp's full-sized avatar

Razvan Grigore razvanphp

  • ABOUT YOU GmbH
  • Hamburg
View GitHub Profile
@razvanphp
razvanphp / yii.dev.router.php
Created November 21, 2019 21:05
Yii2 built-in PHP server router file with dot support in URI + access logs output
<?php
// serve static files
$uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if (file_exists(__DIR__ . '/web' . $uri)) {
return false;
}
// output access log
function output()
@razvanphp
razvanphp / recv.vcl
Last active March 21, 2017 16:17
normalize request params & strip cookies in varnish
sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you
# don't need, rewriting the request, etc.
if ((req.url ~ "^/$" ||
req.url ~ "^/(frauen|maenner|kinder|outlet|marke)(/.+)?" ||
req.url ~ "^/api/(seen2bought/|similarProduct/|product\?)" ||
req.url ~ "\.(css|js)\?.*" ||
@razvanphp
razvanphp / init.vcl
Created March 21, 2017 15:48
round robin backends in varnish
import directors;
backend ay_p_www1 {
.host = "10.10.0.137";
.port = "80";
.probe = {
.url = "/status";
.timeout = 1s;
.interval = 5s;
.window = 5;
@razvanphp
razvanphp / hash.vcl
Created March 21, 2017 15:47
ignore UTM parameters from varnish hashing function
sub vcl_hash {
# Strip out Google Analytics campaign variables
# They are only needed by the javascript running on the page
# utm_source, utm_medium, utm_campaign, gclid, …
hash_data(regsub(regsuball(req.url, "(vid|ef_id|gclid|kw|cof|siteurl|zanpid|origin|emst|sc_[a-z]+|utm_[a-z]+|mr:[A-z]+)=[%@\.\-\:\+_A-z0–9]+&?", ""), "(\?&|\?|&)$", ""));
if (req.http.X-Forwarded-Proto ~ "^(https|http)$") {
hash_data(req.http.X-Forwarded-Proto);
}
@razvanphp
razvanphp / backend_response.vcl
Last active March 21, 2017 15:49
varnish strip backend cookies
sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie
# headers and other mistakes your backend does.
if (bereq.url ~ "^/$" ||
bereq.url ~ "^/(frauen|maenner|kinder|outlet|marke)(/.+)?" ||
bereq.url ~ "^/api/(seen2bought/|similarProduct/|product\?)" ||
bereq.url ~ "\.(css|js)\?.*" ||