Last active
October 24, 2015 15:41
-
-
Save AlekseyKorzun/c4b0d57f7531e680a09f to your computer and use it in GitHub Desktop.
Static bandwidth limiting and blacklisting with Lighttpd + Lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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