Skip to content

Instantly share code, notes, and snippets.

@AlekseyKorzun
Last active October 24, 2015 15:41
Show Gist options
  • Save AlekseyKorzun/c4b0d57f7531e680a09f to your computer and use it in GitHub Desktop.
Save AlekseyKorzun/c4b0d57f7531e680a09f to your computer and use it in GitHub Desktop.
Static bandwidth limiting and blacklisting with Lighttpd + Lua
# Lighttpd
$HTTP["referer"] !~ "^($|http://([^/]*\.)?imagesocket\.(com|net|org)/)" {
magnet.attract-physical-path-to = ("/www/sites/conf/imagesocket/bandwidth.lua")
}
# Lua check for images that exceeded limit(S)
# Path - Flag - Expiration
local url_check =
{
["/images/2012/08/20/1.png"] = true, -- 1352167206
}
if url_check[lighty.env["uri.path"]] then
lighty.env["uri.path"] = "/limited.gif"
lighty.env["physical.rel-path"] = lighty.env["uri.path"]
lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
end
include "/www/sites/conf/imagesocket/blacklist.conf"
# Sample Blacklist
$HTTP["referer"] =~ "^http://(75.*|69.*)" {
url.rewrite = ("(?i)(/.*\.(jpe?g|png|gif))$" => "/banned.gif" )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment