Varnish日志切割+参数优化

 varnishncsa -n /usr/local/varnish/ -w /var/log/varnish.log &    //简化日志的输出
#!/bin/bash
# This is varnish http type log
if [ "$1" = "start" ]; then
/usr/local/bin/varnishncsa -n /usr/local/varnish | /usr/sbin/rotatelogs /var/log/varnish.%Y.%m.%d.log 3600 480 &    //3600秒,表示每小时生成一个日志,480分钟表示UTC时差为8小时。因为中国在东八区。否则生成的时间比正确时间少8小时。
elif [ "$1" = "stop" ]; then
killall varnishncsa
else
echo $0 "{ start | stop }"
fi
net.ipv4.ip_local_port_range = 1024 65535
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_fin_timeout = 30
net.core.netdev_max_backlog = 30000
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
启动压缩功能(注:varnish本身没有压缩功能,需要交给后端服务器)
if (req.http.Accept-Encoding) {
        if (req.url ~ "\.(jpg|gif|png|gz|tgz|mp3)$") {
        remove req.http.Accept-Encoding;
        } else if (req.http.Accept-Encoding ~ "gzip") {
                set req.http.Accept-Encoding = "gzip";
        } else if ( req.http.Accept-Encoding ~ "default") {
                set req.http.Accept-Encoding = "default";
        } else {
                remove req.http.Accept-Encoding;
        }
}
sub vcl_hash {
        set req.hash += req.url;
        if (req.http.Accept-Encoding ~ "gzip") {
        set req.hash += "gzip";
        }
        else if (req.http.Accept-Encoding ~ "default") {
        set req.hash += "default";
        }
        return (hash);
        }
防盗链图片:
if (req.http.referer ~ "http://.*") { if ( !(req.http.referer ~ "http://.*benet\.com" || req.http.referer ~ "http://.*baidu\.com" || req.http.referer ~ "http://.*google\.com" || req.http.referer ~ "http://.*yahoo\.cn") { set req.http.host = "www.benet.com"; set req.url = "/var/www/html/images/logo.gif"; } return (lookup) }

 

转载于:https://www.cnblogs.com/chenwz/p/10648250.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值