{"id":731,"date":"2013-10-18T11:34:36","date_gmt":"2013-10-18T09:34:36","guid":{"rendered":"http:\/\/blog.jeremm.fr\/?p=731"},"modified":"2014-09-24T19:41:26","modified_gmt":"2014-09-24T17:41:26","slug":"varnish-vmod-throttle","status":"publish","type":"post","link":"https:\/\/blog.jeremm.fr\/?p=731","title":{"rendered":"Varnish vmod-throttle"},"content":{"rendered":"<p>Pour limiter le nombre de requ\u00eates par IP, vous pouvez installer le vmod throttle.<br \/>\nVoici le fichier compil\u00e9 pour varnish 3.0.4 \u00e0 placer sous debian dans \/usr\/lib\/varnish\/vmods :<br \/>\n<a href=\"http:\/\/blog.jeremm.fr\/libvmod_throttle.so.3.0.4.tar\" title=\"libvmod_throttle.so.3.0.4.tar\" target=\"_blank\">libvmod_throttle.so.3.0.4.tar<\/a><br \/>\n<strong>MAJ<\/strong> : Voici le fichier compil\u00e9 pour varnish 3.0.5 \u00e0 placer sous debian dans \/usr\/lib\/varnish\/vmods :<br \/>\n<a href=\"http:\/\/blog.jeremm.fr\/libvmod_throttle.so.3.0.5.tar\" title=\"libvmod_throttle.so.3.0.5.tar\" target=\"_blank\">libvmod_throttle.so.3.0.5.tar<\/a><br \/>\n<strong>MAJ<\/strong> : Voici le fichier compil\u00e9 pour varnish 3.0.3 \u00e0 placer sous debian dans \/usr\/lib\/varnish\/vmods :<br \/>\n<a href=\"http:\/\/blog.jeremm.fr\/libvmod_throttle.so.3.0.3.tar\" title=\"libvmod_throttle.so.3.0.3.tar\" target=\"_blank\">libvmod_throttle.so.3.0.3.tar<\/a><br \/>\nIl faut ensuite ajouter dans la configuration en premier lieu:<\/p>\n<pre lang=\"cpp\">import throttle;<\/pre>\n<p>puis dans le vcl_recv :<\/p>\n<pre lang=\"cpp\">if(throttle.is_allowed(\"ip:\" + client.ip, \"20req\/s\") > 0s) {\r\n\ufeff        error 429 \"Calm down\";\r\n}<\/pre>\n<p>Vous pouvez pr\u00e9ciser plusieurs ratios entre les guillemets :<\/p>\n<pre lang=\"cpp\">\ufeff20req\/s, 200req\/30s, 1000req\/5m, 2000req\/h<\/pre>\n<p>Les unit\u00e9s de temps possibles sont : s,m,h,d<\/p>\n<p>Vous pouvez exclure des IPs en utilisant une acl :<\/p>\n<pre lang=\"cpp\">acl allowIP {\r\n        \"127.0.0.1\";\r\n}\r\n\r\nsub vcl_recv {\r\n        if (!client.ip ~ allowIP) {\r\n                if(throttle.is_allowed(\"ip:\" + client.ip, \"20req\/s\") > 0s) {\r\n                        error 429 \"Calm down\";\r\n                }\r\n        }\r\n}<\/pre>\n<p>Vous pouvez aussi changer comment il applique le ratio, par exemple par user-agent :<\/p>\n<pre lang=\"cpp\">if(throttle.is_allowed(req.http.user-agent, \"20req\/s\") > 0s) {<\/pre>\n<p>On peut aussi appliquer le ratio que sur les miss par ip par exemple :<\/p>\n<pre lang=\"cpp\">sub vcl_miss {\r\n    if(req.url !~ \"\\.(jpg|jpeg|png|gif|ico|swf|css|js|html|htm)$\") {\r\n         if(throttle.is_allowed(\"miss:\" + client.ip, \"20req\/s\") > 0s) {\r\n               error 429 \"Calm down\";\r\n         }\r\n    }\r\n}<\/pre>\n<p>Lien : <a href=\"https:\/\/github.com\/nand2\/libvmod-throttle\" title=\"https:\/\/github.com\/nand2\/libvmod-throttle\">https:\/\/github.com\/nand2\/libvmod-throttle<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pour limiter le nombre de requ\u00eates par IP, vous pouvez installer le vmod throttle. Voici le fichier compil\u00e9 pour varnish 3.0.4 \u00e0 placer sous debian dans \/usr\/lib\/varnish\/vmods : libvmod_throttle.so.3.0.4.tar MAJ : Voici le fichier compil\u00e9 pour varnish 3.0.5 \u00e0 placer sous debian dans \/usr\/lib\/varnish\/vmods : libvmod_throttle.so.3.0.5.tar MAJ : Voici le fichier compil\u00e9 pour varnish 3.0.3 <a href='https:\/\/blog.jeremm.fr\/?p=731' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[35,34,49,9],"_links":{"self":[{"href":"https:\/\/blog.jeremm.fr\/index.php?rest_route=\/wp\/v2\/posts\/731"}],"collection":[{"href":"https:\/\/blog.jeremm.fr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jeremm.fr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jeremm.fr\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jeremm.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=731"}],"version-history":[{"count":26,"href":"https:\/\/blog.jeremm.fr\/index.php?rest_route=\/wp\/v2\/posts\/731\/revisions"}],"predecessor-version":[{"id":873,"href":"https:\/\/blog.jeremm.fr\/index.php?rest_route=\/wp\/v2\/posts\/731\/revisions\/873"}],"wp:attachment":[{"href":"https:\/\/blog.jeremm.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=731"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jeremm.fr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=731"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jeremm.fr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=731"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}