Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just installed and configured Varnish to work on port 80, and Apache to work on port 8080. I am trying to start Varnish with the command service varnish start, but it gave me this error:

varnishd dead but pid file exists

I edited this configuration in the /etc/sysconfig/varnish:

DAEMON_OPTS="-a :80 \
         -T localhost:6082 \
         -f /etc/varnish/default.vcl \
         -u varnish -g varnish \
         -S /etc/varnish/secret \
         -s file,/var/lib/varnish/varnish_storage.bin,1G"

This is the content of the default.vcl file:

backend default {
  .host = "";
  .port = "8080";
  .connect_timeout = 600s;
  .first_byte_timeout = 600s;
  .between_bytes_timeout = 600s;

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. 
      return (pipe);

  if (req.request != "GET" && req.request != "HEAD") {
    // We only deal with GET and HEAD by default
    return (pass);

  // Remove has_js and Google Analytics cookies.
  set req.http.Cookie = regsuball(req.http.Cookie, 
"(^|;\s*)(__[a-z]+|__utma_a2a|has_js)=[^;]*", "");

  // To users: if you have additional cookies being set by your system 
  // from a javascript analytics file or similar) you will need to add 
  // at this point to strip these cookies from the req object, otherwise
  // Varnish will not cache the response. This is safe for cookies that 
  // backend (Drupal) doesn't process.
  // Again, the common example is an analytics or other Javascript 
  // You should do this here, before the other cookie stuff, or by 
  // to the regular-expression above.

  // Remove a ";" prefix, if present.
  set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
  // Remove empty cookies.
  if (req.http.Cookie ~ "^\s*$") {
    unset req.http.Cookie;

  if (req.http.Authorization || req.http.Cookie) {
    // Not cacheable by default 
    return (pass);

  // Skip the Varnish cache for install, update, and cron
  if (req.url ~ "install\.php|update\.php|cron\.php") {
    return (pass);

  // Normalize the Accept-Encoding header
  // as per:
  if (req.http.Accept-Encoding) {
    if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
      # No point in compressing these
      remove req.http.Accept-Encoding;
    elsif (req.http.Accept-Encoding ~ "gzip") {
      set req.http.Accept-Encoding = "gzip";
    else {
      # Unknown or deflate algorithm
      remove req.http.Accept-Encoding;

  // Let's have a little grace
  set req.grace = 30s;

  return (lookup);

sub vcl_hash {
  if (req.http.Cookie) {
    hash_data (req.http.Cookie);

// Strip any cookies before an image/js/css is inserted into cache.
sub vcl_fetch {
  if (req.url ~ "\.(png|gif|jpg|swf|css|js)$") {
    // For Varnish 2.0 or earlier, replace beresp with obj:
    // unset obj.http.set-cookie;
    unset beresp.http.set-cookie;

// Set a header to track a cache HIT/MISS.
sub vcl_deliver {
  if (obj.hits > 0) {
    set resp.http.X-Varnish-Cache = "HIT";
  else {
    set resp.http.X-Varnish-Cache = "MISS";

sub vcl_error {
  // Let's deliver a friendlier error page.
  // You can customize this as you wish.
  set obj.http.Content-Type = "text/html; charset=utf-8";
  synthetic {"
  <?xml version="1.0" encoding="utf-8"?>
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      <title>"} + obj.status + " " + obj.response + {"</title>
      <style type="text/css">
      #page {width: 400px; padding: 10px; margin: 20px auto; border: 1px 
solid black; background-color: #FFF;}
      p {margin-left:20px;}
      body {background-color: #DDD; margin: auto;}
    <div id="page">
    <h1>Page Could Not Be Loaded</h1>
    <p>We're very sorry, but the page could not be loaded properly. This 
should be fixed very soon, and we apologize for any inconvenience.</p>
    <hr />
    <h4>Debug Info:</h4>
    <pre>Status: "} + obj.status + {"
Response: "} + obj.response + {"
XID: "} + req.xid + {"</pre>

How do I fix this problem?

share|improve this question

. . . make sure Varnish isn't running, and if it's not delete the PID file?

share|improve this answer
Varnish is not working and whenever i delete the file from /var/run/ it's recreated again – M.B.Asfour Apr 17 '12 at 16:10
@M.B.Asfoor See, now telling us what you've already tried would be something important to put in your question: Varnish is starting and dying - If you want help troubleshooting that you need to give us something to work with (log files are a good start, so is console output when you run Varnish manually from the command line) – voretaq7 Apr 17 '12 at 16:13
i have added some details in the question i reviewed the logs and didn't find any thing unusual – M.B.Asfour Apr 17 '12 at 16:34

Check the secret file in /etc/varnish. It must have a value.

share|improve this answer
The secret file, or the PID file? And what should he do once he finds it? – Falcon Momot Aug 27 '13 at 23:32
For the secret file, ensure there is a hash similar to the value seen with a fresh install. This is just a possibility but was the solution for me with identical symptoms. – bighappyface Aug 27 '13 at 23:34
Neat article to help, just in case: – bighappyface Aug 27 '13 at 23:39
If it's a hunch it's probably better suited for a comment. – Drew Khoury Aug 28 '13 at 0:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.