<div dir="ltr">Hi Guys,<div><br></div><div>I've just setup Varnish on CentOS 6.2 via the official RPM and I'm hoping someone can help me to get it working!</div><div><br></div><div style>It seems Varnish doesn't reference DAEMON_OPTS in /etc/sysconfig/varnish, because it will always bind to ports 6081 and 6082, as seen in the netstat -tulpn results below:</div>
<div style><br></div><div style><div>tcp 0 0 <a href="http://0.0.0.0:6081">0.0.0.0:6081</a> 0.0.0.0:* LISTEN 22844/varnishd </div><div>tcp 0 0 <a href="http://127.0.0.1:6082">127.0.0.1:6082</a> 0.0.0.0:* LISTEN 22843/varnishd </div>
<div><div>tcp 0 0 :::6081 :::* LISTEN 22844/varnishd</div></div><div><br></div><div style>Even after continuously restarting / reloading varnish, killing the process etc, it wont bind on the desired port (80)</div>
<div style><br></div><div style>I am starting varnish by running "service varnish start"</div></div><div><br></div><div>Here is my config for /etc/sysconfig/varnish:</div><div><br></div><div>=========</div><div>
<div># Configuration file for varnish</div><div>#</div><div># /etc/init.d/varnish expects the variable $DAEMON_OPTS to be set from this</div><div># shell script fragment.</div><div>#</div><div><br></div><div># Maximum number of open files (for ulimit -n)</div>
<div>NFILES=131072</div><div><br></div><div># Locked shared memory (for ulimit -l)</div><div># Default log size is 82MB + header</div><div>MEMLOCK=82000</div><div><br></div><div># Maximum size of corefile (for ulimit -c). Default in Fedora is 0</div>
<div># DAEMON_COREFILE_LIMIT="unlimited"</div><div><br></div><div># Set this to 1 to make init script reload try to switch vcl without restart.</div><div># To make this work, you need to set the following variables</div>
<div># explicit: VARNISH_VCL_CONF, VARNISH_ADMIN_LISTEN_ADDRESS,</div><div># VARNISH_ADMIN_LISTEN_PORT, VARNISH_SECRET_FILE, or in short,</div><div># use Alternative 3, Advanced configuration, below</div><div>RELOAD_VCL=1</div>
<div><br></div><div># This file contains 4 alternatives, please use only one.</div><div><br></div><div>## Alternative 1, Minimal configuration, no VCL</div><div>#</div><div># Listen on port 6081, administration on localhost:6082, and forward to</div>
<div># content server on localhost:8080. Use a fixed-size cache file.</div><div>#</div><div><br></div><div>## Alternative 2, Configuration with VCL</div><div>#</div><div># Listen on port 6081, administration on localhost:6082, and forward to</div>
<div># one content server selected by the vcl file, based on the request. Use a</div><div># fixed-size cache file.</div><div>#</div><div><br></div><div>DAEMON_OPTS="-a :80 \</div><div> -T localhost:6081 \</div>
<div> -f /etc/varnish/default.vcl \</div><div> -u varnish -g varnish \</div><div> -S /etc/varnish/secret \</div><div> -s file,/var/lib/varnish/varnish_storage.bin,1G"</div>
<div><br></div><div><br></div><div>## Alternative 3, Advanced configuration</div><div>#</div><div># See varnishd(1) for more information.</div><div>#</div><div># # Main configuration file. You probably want to change it :)</div>
<div>VARNISH_VCL_CONF=/etc/varnish/default.vcl</div><div>#</div><div># # Default address and port to bind to</div><div># # Blank address means all IPv4 and IPv6 interfaces, otherwise specify</div><div># # a host name, an IPv4 dotted quad, or an IPv6 address in brackets.</div>
<div># VARNISH_LISTEN_ADDRESS=</div><div>VARNISH_LISTEN_PORT=6081</div><div>#</div><div># # Telnet admin interface listen address and port</div><div>VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1</div><div>VARNISH_ADMIN_LISTEN_PORT=6082</div>
<div>#</div><div># # Shared secret file for admin interface</div><div>VARNISH_SECRET_FILE=/etc/varnish/secret</div><div>#</div><div># # The minimum number of worker threads to start</div><div>VARNISH_MIN_THREADS=1</div><div>
#</div><div># # The Maximum number of worker threads to start</div><div>VARNISH_MAX_THREADS=1000</div><div>#</div><div># # Idle timeout for worker threads</div><div>VARNISH_THREAD_TIMEOUT=120</div><div>#</div><div># # Cache file location</div>
<div>VARNISH_STORAGE_FILE=/var/lib/varnish/varnish_storage.bin</div><div>#</div><div># # Cache file size: in bytes, optionally using k / M / G / T suffix,</div><div># # or in percentage of available disk space using the % suffix.</div>
<div>VARNISH_STORAGE_SIZE=1G</div><div>#</div><div># # Backend storage specification</div><div>VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},${VARNISH_STORAGE_SIZE}"</div><div>#</div><div># # Default TTL used when the backend does not specify one</div>
<div>VARNISH_TTL=120</div><div>#</div><div># # DAEMON_OPTS is used by the init script. If you add or remove options, make</div><div># # sure you update this section, too.</div><div>DAEMON_OPTS="-a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} \</div>
<div> -f ${VARNISH_VCL_CONF} \</div><div> -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} \</div><div> -t ${VARNISH_TTL} \</div><div> -w ${VARNISH_MIN_THREADS},${VARNISH_MAX_THREADS},${VARNISH_THREAD_TIMEOUT} \</div>
<div> -u varnish -g varnish \</div><div> -S ${VARNISH_SECRET_FILE} \</div><div> -s ${VARNISH_STORAGE}"</div><div>#</div><div><br></div><div><br></div><div>## Alternative 4, Do It Yourself. See varnishd(1) for more information.</div>
<div>#</div><div># DAEMON_OPTS=""</div></div><div>=========</div><div><br></div><div>& Here is my VCL : /etc/varnish/default.vcl</div><div><br></div><div>=========</div><div><div># This is a basic VCL configuration file for varnish. See the vcl(7)</div>
<div># man page for details on VCL syntax and semantics.</div><div># </div><div># Default backend definition. Set this to point to your content</div><div># server.</div><div># </div><div>backend default {</div><div> .host = "127.0.0.1";</div>
<div> .port = "8080";</div><div>}</div><div># </div><div># Below is a commented-out copy of the default VCL logic. If you</div><div># redefine any of these subroutines, the built-in logic will be</div><div># appended to your code.</div>
<div># sub vcl_recv {</div><div># if (req.restarts == 0) {</div><div># <span class="" style="white-space:pre"> </span>if (req.http.x-forwarded-for) {</div><div># <span class="" style="white-space:pre"> </span> set req.http.X-Forwarded-For =</div>
<div># <span class="" style="white-space:pre"> </span>req.http.X-Forwarded-For + ", " + client.ip;</div><div># <span class="" style="white-space:pre"> </span>} else {</div><div># <span class="" style="white-space:pre"> </span> set req.http.X-Forwarded-For = client.ip;</div>
<div># <span class="" style="white-space:pre"> </span>}</div><div># }</div><div># if (req.request != "GET" &&</div><div># req.request != "HEAD" &&</div><div># req.request != "PUT" &&</div>
<div># req.request != "POST" &&</div><div># req.request != "TRACE" &&</div><div># req.request != "OPTIONS" &&</div><div># req.request != "DELETE") {</div>
<div># /* Non-RFC2616 or CONNECT which is weird. */</div><div># return (pipe);</div><div># }</div><div># if (req.request != "GET" && req.request != "HEAD") {</div><div>
# /* We only deal with GET and HEAD by default */</div>
<div># return (pass);</div><div># }</div><div># if (req.http.Authorization || req.http.Cookie) {</div><div># /* Not cacheable by default */</div><div># return (pass);</div><div># }</div>
<div># return (lookup);</div><div># }</div><div># </div><div># sub vcl_pipe {</div><div># # Note that only the first request to the backend will have</div><div># # X-Forwarded-For set. If you use X-Forwarded-For and want to</div>
<div># # have it set for all requests, make sure to have:</div><div># # set bereq.http.connection = "close";</div><div># # here. It is not set by default as it might break some broken web</div><div>
# # applications, like IIS with NTLM authentication.</div><div># return (pipe);</div><div># }</div><div># </div><div># sub vcl_pass {</div><div># return (pass);</div><div># }</div><div># </div><div># sub vcl_hash {</div>
<div># hash_data(req.url);</div><div># if (req.http.host) {</div><div># hash_data(req.http.host);</div><div># } else {</div><div># hash_data(server.ip);</div><div># }</div><div># return (hash);</div>
<div># }</div><div># </div><div># sub vcl_hit {</div><div># return (deliver);</div><div># }</div><div># </div><div># sub vcl_miss {</div><div># return (fetch);</div><div># }</div><div># </div><div># sub vcl_fetch {</div>
<div># if (beresp.ttl <= 0s ||</div><div># beresp.http.Set-Cookie ||</div><div># beresp.http.Vary == "*") {</div><div># <span class="" style="white-space:pre"> </span>/*</div><div># <span class="" style="white-space:pre"> </span> * Mark as "Hit-For-Pass" for the next 2 minutes</div>
<div># <span class="" style="white-space:pre"> </span> */</div><div># <span class="" style="white-space:pre"> </span>set beresp.ttl = 120 s;</div><div># <span class="" style="white-space:pre"> </span>return (hit_for_pass);</div>
<div># }</div><div># return (deliver);</div><div># }</div><div># </div><div># sub vcl_deliver {</div><div># return (deliver);</div><div># }</div><div># </div><div># sub vcl_error {</div><div># set obj.http.Content-Type = "text/html; charset=utf-8";</div>
<div># set obj.http.Retry-After = "5";</div><div># synthetic {"</div><div># <?xml version="1.0" encoding="utf-8"?></div><div># <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"</div>
<div># "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</a>"></div><div># <html></div><div># <head></div><div># <title>"} + obj.status + " " + obj.response + {"</title></div>
<div># </head></div><div># <body></div><div># <h1>Error "} + obj.status + " " + obj.response + {"</h1></div><div># <p>"} + obj.response + {"</p></div>
<div># <h3>Guru Meditation:</h3></div><div># <p>XID: "} + req.xid + {"</p></div><div># <hr></div><div># <p>Varnish cache server</p></div><div># </body></div>
<div># </html></div><div># "};</div><div># return (deliver);</div><div># }</div><div># </div><div># sub vcl_init {</div><div># <span class="" style="white-space:pre"> </span>return (ok);</div><div># }</div>
<div># </div><div># sub vcl_fini {</div><div># <span class="" style="white-space:pre"> </span>return (ok);</div><div># }</div></div><div>=========</div><div><br></div><div style>Hoping you experts can help!</div><div><div>
<br></div>-- <br>Regards,<div><br></div><div>Drew Morris</div>
</div></div>