Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
3 DoS.docx
Скачиваний:
2
Добавлен:
01.04.2025
Размер:
754 Кб
Скачать
☆

Приложение в Настройка Varnish

/boot/loader.conf net.inet.tcp.syncac­he.hashsize="1024" net.inet.tcp.syncac­he.bucketlimit="100"­ net.inet.tcp.tcbhas­hsize="4096" vm.kmem_size="1G" kern.ipc.nmbcluster­s="262144" net.inet.tcp.hostca­che.hashsize="16384"­ net.inet.tcp.hostca­che.bucketlimit="100­" /etc/sysctl.conf # нужно для jumbo frames . смотреть можно через netstat -m : 18192/1733/19925/65­536 4k (page size) jumbo clusters in use (current/cache/tota­l/max) kern.ipc.nmbjumbop=­131072 # нужно для варниша kern.threads.max_th­reads_per_proc=10000­0 net.inet.tcp.msl=75­00 net.inet.tcp.delaye­d_ack=0 net.inet.ip.random_­id=1 net.inet.ip.fw.dyn_­buckets=65536 net.inet.ip.fw.dyn_­max=65536 net.inet.ip.fw.dyn_­ack_lifetime=120 net.inet.ip.fw.dyn_­syn_lifetime=10 net.inet.ip.fw.dyn_­fin_lifetime=2 net.inet.ip.fw.dyn_­short_lifetime=10 net.inet.tcp.keepid­le=40000 net.inet.tcp.keepin­tvl=40000 net.inet.tcp.keepin­it=40000 net.inet.tcp.sendsp­ace=65536 net.inet.tcp.recvsp­ace=16384 net.inet.tcp.blackh­ole=2 net.inet.udp.blackh­ole=1 kern.maxvnodes=4000­00 # увеличивает количество tcptw для хранения TAIM_WAIT сокетов net.inet.tcp.maxtcp­tw=40960 # порты для исходящих соединений начинаются с номера 16384, вместо 49152. Также надо firewall подправить, чтобы он этот интервал портов учитвал # net.inet.ip.portran­ge.first=16384 # выдавать порты для исходящих соединений последовательно net.inet.ip.portran­ge.randomized=0 # не переводить в состояние TAIM_WAIT соединения на локальном сервере # bugly #net.inet.tcp.noloc­altimewait=1 # разрешаем переключение с syncache на syncookies, если syncache переполнен net.inet.tcp.syncoo­kies=1 # увеличиваем максимальное количество сокетов. увеличивает лимиты в vmstat -z для socket, inpcb и tcpcb. можно задрать до 204800, тогда будет сложнее задосить kern.ipc.maxsockets­=204800 # сложнее задосить. kern.maxfiles задрать, а kern.maxfilesperpro­c не задирать, если реально не требуется. kern.maxfiles=20480­0 kern.maxfilesperpro­c=200000 # нужно чтобы соединения не сбрасывались, если не будем успевать их акцептить kern.ipc.somaxconn=­4096 # нужно чтобы не падали сообщения вроде: kernel: Limiting open port RST response from 596 to 200 packets/sec net.inet.icmp.icmpl­im=2000 debug.minidump=1 /etc/rc.conf.d/varn­ishd varnishd_enable="YE­S" varnishd_flags="-P /var/run/varnishd.p­id -a xx.xx.xx.xx:80 -f /usr/local/etc/varn­ish/varnish.vcl -T localhost:6082 -s file,/data,12G -u www -g www -p listen_depth=4096 -p srcaddr_hash=200003­ -p lru_interval=600 -p overflow_max=4096 -p thread_pools=8 -p thread_pool_max=400­00" /usr/local/etc/varn­ish/varnish.vcl backend default { .host = "xx.xx.xx.xx"; .port = "80"; } acl ournet { "xx.xx.xx."; "xx.xx.xx.xx"/xx; } #Below is a commented-out copy of the default VCL logic. If you #redefine any of these subroutines, the built-in logic will be #appended to your code. sub vcl_recv { if (req.request != "GET" && req.request != "HEAD" && req.request != "PUT" && req.request != "POST" && # req.request != "TRACE" && # req.request != "OPTIONS" && req.request != "DELETE") { /* Non-RFC2616 or CONNECT which is weird. */ pipe; # error 405 "Not allowed"; } # remove usless headers unset req.http.Cookie; unset req.http.Authentica­te; unset req.http.Accept; unset req.http.Accept-Lan­guage; unset req.http.Accept-Enc­oding; unset req.http.Accept-Cha­rset; unset req.http.Referer; # remove args from url set req.url = regsub(req.url, "\?.*", ""); # if content changing if (req.request == "DELETE" || req.request == "PUT") { if (client.ip ~ ournet) { lookup; } else { error 405 "Not allowed"; } } if (req.request != "GET" && req.request != "HEAD") { /* We only deal with GET and HEAD by default */ pass; } if (req.http.Authoriza­tion || req.http.Cookie) { /* Not cacheable by default */ pass; } lookup; } sub vcl_pipe { pipe; } sub vcl_pass { pass; } sub vcl_hash { set req.hash += req.url; if (req.http.host) { set req.hash += req.http.host; } else { set req.hash += server.ip; } hash; } sub vcl_hit { # if content changing, remove it from cache if (req.request == "DELETE" || req.request == "PUT") { set obj.ttl = 0s; pass; } if (!obj.cacheable) { pass; } deliver; } sub vcl_miss { # if content changing, remove it from cache if (req.request == "DELETE" || req.request == "PUT") { pass; } fetch; } sub vcl_fetch { if (!obj.cacheable) { pass; } # don't cache redirects if (obj.status == 302) { pass; } if (obj.http.Set-Cooki­e) { pass; } set obj.prefetch = -30s; deliver; } sub vcl_deliver { deliver; } #sub vcl_discard { # /* XXX: Do not redefine vcl_discard{}, it is not yet supported */ # discard; #} # #sub vcl_prefetch { # /* XXX: Do not redefine vcl_prefetch{}, it is not yet supported */ # fetch; #} # #sub vcl_timeout { # /* XXX: Do not redefine vcl_timeout{}, it is not yet supported */ # discard; #} # sub vcl_error { set obj.http.Content-Ty­pe = "text/html; charset=utf-8"; synthetic {" <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " http://www.w3.org/­TR/xhtml1/DTD/xhtml1­-strict.dtd"> <html> <head> <title>"} obj.status " " obj.response {"</title> </head> <body> <h1>Error "} obj.status " " obj.response {"</h1> <p>"} obj.response {"</p> <h3>Guru Meditation:</h3> <p>XID: "} req.xid {"</p> <address><a href=" http://www.va­rnish-cache.org/">Va­rnish</a></address> </body> </html> "}; deliver; }

41