Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

So I setup a new cloud based instance with Ubuntu 12.04, with nginx, php5-fpm and varnish.

Before I installed and configured Varnish, the website worked fine, virtual hosts worked. After setting up varnish I'm getting Error 503 Service Unavailable now.

My nginx conf looks like this:

server {
   listen xxx.xxx.xxx.xxx:8080;
   server_name example.com ;
   root /var/www/example.com/public_html;
   if ($http_host != "example.com") {
             rewrite ^ http://www.example.com$request_uri permanent;
   }
   index index.php index.html;
   location = /favicon.ico {
            log_not_found off;
            access_log off;
   }
   location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
   }
   # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
   location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;
   }
   location / {
            try_files $uri $uri/ /index.php?$args;
   }
   # Add trailing slash to */wp-admin requests.
   rewrite /wp-admin$ $scheme://$host$uri/ permanent;
   location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
            expires max;
            log_not_found off;
   }
   location ~ \.php$ {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   }

    #Roots theme clean URL rewrites
    location ~ ^/assets/(img|js|css)/(.*)$ {
      try_files $uri $uri/ /wp-content/themes/sitename/assets/$1/$2;
    }
    location ~ ^/plugins/(.*)$ {
      try_files $uri $uri/ /wp-content/plugins/$1;
    }

}

/etc/default/varnish looks like the this:

# Configuration file for varnish
#
# /etc/init.d/varnish expects the variables $DAEMON_OPTS, $NFILES and $MEMLOCK
# to be set from this shell script fragment.
#
# Note: If systemd is installed, this file is obsolete and ignored.  You will
# need to copy /lib/systemd/system/varnish.service to /etc/systemd/system/ and
# edit that file.

# Should we start varnishd at boot?  Set to "no" to disable.
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 malloc,256m"

/etc/varnish/default.vcl looks like the following:

 backend default {
.host = "xxx.xxx.xxx.xxx";
.port = "8080";    }

Checking varnishlog I see this:

11 SessionOpen  c xx.xxx.xxx.xxx 4712 :80
11 ReqStart     c xx.xxx.xxx.xxx 4712 1475226459
11 RxRequest    c GET
11 RxURL        c /
11 RxProtocol   c HTTP/1.1
11 RxHeader     c Host: example.com
11 RxHeader     c Connection: keep-alive
11 RxHeader     c Cache-Control: max-age=0
11 RxHeader     c Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
11 RxHeader     c User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.155 Safari/537.22
11 RxHeader     c Accept-Encoding: gzip,deflate,sdch
11 RxHeader     c Accept-Language: en-US,en;q=0.8
11 RxHeader     c Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
11 RxHeader     c Cookie: __utma=148547044.766489551.1362139914.1362151355.1362156101.3; __utmz=148547044.1362139914.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __cfduid=d92c50421d4bba63041d6d12ba960d3151362551863; wordpress_test_cookie=WP+Cookie+check; wordpress_lo
11 VCL_call     c recv lookup
11 VCL_call     c hash
11 Hash         c /
11 Hash         c example.com
11 VCL_return   c hash
11 VCL_call     c miss fetch
11 FetchError   c no backend connection
11 VCL_call     c error deliver
11 VCL_call     c deliver deliver
11 TxProtocol   c HTTP/1.1
11 TxStatus     c 503
11 TxResponse   c Service Unavailable
11 TxHeader     c Server: Varnish
11 TxHeader     c Content-Type: text/html; charset=utf-8
11 TxHeader     c Retry-After: 5
11 TxHeader     c Content-Length: 419
11 TxHeader     c Accept-Ranges: bytes
11 TxHeader     c Date: Wed, 06 Mar 2013 20:14:13 GMT
11 TxHeader     c X-Varnish: 1475226459
11 TxHeader     c Age: 0
11 TxHeader     c Via: 1.1 varnish
11 TxHeader     c Connection: close
11 Length       c 419
11 ReqEnd       c 1475226459 1362600853.513662100 1362600853.513980627 0.000180006 0.000249863 0.000068665
11 SessionClose c error
11 StatSess     c 70.194.150.230 4712 0 1 1 0 0 0 257 419
11 SessionOpen  c 70.194.150.230 4713 :80
11 ReqStart     c 70.194.150.230 4713 1475226460
11 RxRequest    c GET
11 RxURL        c /favicon.ico
11 RxProtocol   c HTTP/1.1
11 RxHeader     c Host: example.com
11 RxHeader     c Connection: keep-alive
11 RxHeader     c Accept: */*
11 RxHeader     c User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.155 Safari/537.22
11 RxHeader     c Accept-Encoding: gzip,deflate,sdch
11 RxHeader     c Accept-Language: en-US,en;q=0.8
11 RxHeader     c Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
11 VCL_call     c recv lookup
11 VCL_call     c hash
11 Hash         c /favicon.ico
11 Hash         c example.com
11 VCL_return   c hash
11 VCL_call     c miss fetch
11 FetchError   c no backend connection
11 VCL_call     c error deliver
11 VCL_call     c deliver deliver
11 TxProtocol   c HTTP/1.1
11 TxStatus     c 503
11 TxResponse   c Service Unavailable
11 TxHeader     c Server: Varnish
11 TxHeader     c Content-Type: text/html; charset=utf-8
11 TxHeader     c Retry-After: 5
11 TxHeader     c Content-Length: 419
11 TxHeader     c Accept-Ranges: bytes
11 TxHeader     c Date: Wed, 06 Mar 2013 20:14:13 GMT
11 TxHeader     c X-Varnish: 1475226460
11 TxHeader     c Age: 0
11 TxHeader     c Via: 1.1 varnish
11 TxHeader     c Connection: close
11 Length       c 419
11 ReqEnd       c 1475226460 1362600853.751207590 1362600853.751491070 0.000154257 0.000221491 0.000061989
11 SessionClose c error
11 StatSess     c 70.194.150.230 4713 0 1 1 0 0 0 257 419
share|improve this question
    
Can you please paste complete /etc/varnish/default.vcl file here. I believe what you pasted is not the complete file. –  GeekRide Mar 7 '13 at 7:44

1 Answer 1

It looks like varnish can't connect to your nginx backend - are you able to connect to it by visiting http://xxx.xxx.xxx.xxx:8080 ?

share|improve this answer

Your Answer

 
discard

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.