【问题标题】:Setting up varnish on same server as webserver在与网络服务器相同的服务器上设置清漆
【发布时间】:2011-10-19 02:39:05
【问题描述】:

我们公司最近决定开始使用 Varnish HTTP 加速器。我们选择这个解决方案的最重要原因是因为我们是一家专门建立网上商店的公司(Magento Enterprise)=> Magento 有一个与 varnish 一起工作的商业插件。

varnish 配置已经存在于我们的测试环境中,其中包含 1 个运行 varnish 实例的(软件)负载平衡器、2 个 apache 网络服务器和 1 个存储 + 1 个 mysql 服务器。

但是现在是时候将 Varnish 添加到我们的开发环境中了(具有 1GB 内存的虚拟机运行 debian,数据库、网络服务器、文件都在同一台机器上运行)

谁能为此设置发布一个 default.vcl 配置文件?

Apache2 在 80 端口上运行。

提前致谢, 肯尼

编辑:我在下面找到并发布了the solution

【问题讨论】:

    标签: varnish


    【解决方案1】:

    此链接对在大型生产网站上使用 Varnish 进行了很好的讨论。特别是,查看将缓存“文件”放入内存而不是磁盘的 /etc/default/varnish 或 /etc/sysconfig/varnish DAEMON OPTS:

    http://www.lullabot.com/articles/varnish-multiple-web-servers-drupal

    我说的sn-p:

    DAEMON_OPTS="-a :80,:443 \
                 -T localhost:6082 \
                 -f /etc/varnish/default.vcl \
                 -u varnish -g varnish \
                 -S /etc/varnish/secret \
                 -p thread_pool_add_delay=2 \
                 -p thread_pools=2 \
                 -p thread_pool_min=400 \
                 -p thread_pool_max=4000 \
                 -p session_linger=50 \
                 -p sess_workspace=262144 \
                 -s malloc,3G"
    

    【讨论】:

    【解决方案2】:

    经过更多搜索,我找到了解决方案。基本上我们需要确保 varnish 监听 80 端口,apache 监听 8080 端口(或其他任何东西!)。

    这是我的 default.vcl 文件(位于 /etc/varnish/default.vcl):

    # default backend definition.  Set this to point to your content server.
    backend apache1 {
      .host = "127.0.0.1";
      .port = "8080";
    }
    
    director lb round-robin {
        {.backend=apache1;}
    }
    
    # add your Magento server IP to allow purges from the backend
    acl purge {
      "localhost";
      "127.0.0.1";
    }
    
    # needed for TTL handling
    C{
    #include <errno.h>
    #include <limits.h>
    }C
    
    
    sub vcl_recv {
    
        set req.backend=lb;
    
        if (req.request != "GET" &&
          req.request != "HEAD" &&
          req.request != "PUT" &&
          req.request != "POST" &&
          req.request != "TRACE" &&
          req.request != "OPTIONS" &&
          req.request != "DELETE" &&
          req.request != "PURGE") {
            /* Non-RFC2616 or CONNECT which is weird. */
            return (pipe);
        }
    
        # purge request
        if (req.request == "PURGE") {
            if (!client.ip ~ purge) {
                error 405 "Not allowed.";
            }
            purge("obj.http.X-Purge-Host ~ " req.http.X-Purge-Host " && obj.http.X-Purge-URL ~ " req.http.X-Purge-Regex " && obj.http.Content-Type ~ " req.http.X-Purge-Content-Type);
            error 200 "Purged.";
        }
    
        # we only deal with GET and HEAD by default    
        if (req.request != "GET" && req.request != "HEAD") {
            return (pass);
        }
    
        # static files are always cacheable. remove SSL flag and cookie
        if (req.url ~ "^/(media|js|skin)/.*\.(png|jpg|jpeg|gif|css|js|swf|ico)$") {
            unset req.http.Https;
            unset req.http.Cookie;
        }
    
        # not cacheable by default
        if (req.http.Authorization || req.http.Https) {
            return (pass);
        }
    
        # do not cache any page from
        # - index files
        # - ...
        if (req.url ~ "^/(index)") {
            return (pass);
        }
    
        # as soon as we have a NO_CACHE or admin cookie pass request
        if (req.http.cookie ~ "(NO_CACHE|adminhtml)=") {
            return (pass);
        }
    
        # normalize Aceept-Encoding header
        # http://varnish.projects.linpro.no/wiki/FAQ/Compression
        if (req.http.Accept-Encoding) {
            if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
                # No point in compressing these
                remove req.http.Accept-Encoding;
            } elsif (req.http.Accept-Encoding ~ "gzip") {
                set req.http.Accept-Encoding = "gzip";
            } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
                set req.http.Accept-Encoding = "deflate";
            } else {
                # unkown algorithm
                remove req.http.Accept-Encoding;
            }
        }
    
        # remove Google gclid parameters
        set req.url = regsuball(req.url,"\?gclid=[^&]+$",""); # strips when QS = "?gclid=AAA"
        set req.url = regsuball(req.url,"\?gclid=[^&]+&","?"); # strips when QS = "?gclid=AAA&foo=bar"
        set req.url = regsuball(req.url,"&gclid=[^&]+",""); # strips when QS = "?foo=bar&gclid=AAA" or QS = "?foo=bar&gclid=AAA&bar=baz"
    
        # decided to cache. remove cookie
        #unset req.http.Cookie;
    
        return (lookup);
    }
    

    这是清漆文件(/etc/default/varnish)的内容:

    # Configuration file for varnish
    #
    # /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK
    # to be set from this shell script fragment.
    #
    
    # Should we start varnishd at boot?  Set to "yes" to enable.
    START=yes
    
    # Maximum number of open files (for ulimit -n)
    NFILES=131072
    
    # Maximum locked memory size (for ulimit -l)
    # Used for locking the shared memory log in memory.  If you increase log size,
    # you need to increase this number as well
    MEMLOCK=82000
    
    # Default varnish instance name is the local nodename.  Can be overridden with
    # the -n switch, to have more instances on a single server.
    INSTANCE=$(uname -n)
    
    # This file contains 4 alternatives, please use only one.
    
    ## Alternative 1, Minimal configuration, no VCL
    #
    # Listen on port 6081, administration on localhost:6082, and forward to
    # content server on localhost:8080.  Use a 1GB fixed-size cache file.
    #
    # DAEMON_OPTS="-a :6081 \
    #              -T localhost:6082 \
    #        -b localhost:8080 \
    #        -u varnish -g varnish \
    #            -S /etc/varnish/secret \
    #        -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"
    
    
    ## Alternative 2, Configuration with VCL
    #
    # Listen on port 6081, administration on localhost:6082, and forward to
    # one content server selected by the vcl file, based on the request.  Use a 1GB
    # fixed-size cache file.
    #
    DAEMON_OPTS="-a :80 \
                 -T localhost:6082 \
                 -f /etc/varnish/default.vcl \
                 -S /etc/varnish/secret \
                 -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,1G"
    
    
    ## Alternative 3, Advanced configuration
    #
    # See varnishd(1) for more information.
    #
    # # Main configuration file. You probably want to change it :)
    # VARNISH_VCL_CONF=/etc/varnish/default.vcl
    #
    # # Default address and port to bind to
    # # Blank address means all IPv4 and IPv6 interfaces, otherwise specify
    # # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
    # VARNISH_LISTEN_ADDRESS=
    # VARNISH_LISTEN_PORT=6081
    #
    # # Telnet admin interface listen address and port
    # VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
    # VARNISH_ADMIN_LISTEN_PORT=6082
    #
    # # The minimum number of worker threads to start
    # VARNISH_MIN_THREADS=1
    #
    # # The Maximum number of worker threads to start
    # VARNISH_MAX_THREADS=1000
    #
    # # Idle timeout for worker threads
    # VARNISH_THREAD_TIMEOUT=120
    #
    # # Cache file location
    # VARNISH_STORAGE_FILE=/var/lib/varnish/$INSTANCE/varnish_storage.bin
    #
    # # Cache file size: in bytes, optionally using k / M / G / T suffix,
    # # or in percentage of available disk space using the % suffix.
    # VARNISH_STORAGE_SIZE=1G
    #
    # # File containing administration secret
    # VARNISH_SECRET_FILE=/etc/varnish/secret
    # 
    # # Backend storage specification
    # VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"
    #
    # # Default TTL used when the backend does not specify one
    # VARNISH_TTL=120
    #
    # # DAEMON_OPTS is used by the init script.  If you add or remove options, make
    # # sure you update this section, too.
    # DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \
    #              -f ${VARNISH_VCL_CONF} \
    #              -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \
    #              -t ${VARNISH_TTL} \
    #              -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \
    #          -S ${VARNISH_SECRET_FILE} \
    #              -s ${VARNISH_STORAGE}"
    #
    
    
    ## Alternative 4, Do It Yourself
    #
    # DAEMON_OPTS=""
    

    之后,您可以通过键入来监控 varnish 如何提供内容(来自什么来源) 清漆日志 | grep 网址

    【讨论】:

      【解决方案3】:

      Apache可用于SSL终止(解密),查看http://noosfero.org/Development/Varnish#SSL

      【讨论】:

        猜你喜欢
        • 2014-11-08
        • 1970-01-01
        • 1970-01-01
        • 2020-12-14
        • 1970-01-01
        • 2017-11-26
        • 1970-01-01
        • 2013-06-11
        • 1970-01-01
        相关资源
        最近更新 更多