简体   繁体   中英

Linux Varnish Cache Server - Guru Meditation 503

I have magento website in Linux server (Varnish cache), some of the product details page shows error as

Error 503 Backend fetch failed Guru Meditation: XID: 98757

My website IP is 52.163.xxx.xx

Please find the below details and help me to fix this issue.

/etc/default/varnish

DAEMON_OPTS="-a :8080 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"

/etc/varnish/default.vcl

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

sudo service varnish restart

  • Stopping HTTP accelerator varnishd No /usr/sbin/varnishd found running; none killed. [fail]
  • Starting HTTP accelerator varnishd [fail] bind(): Address already in use bind(): Address already in use Error: Failed to open (any) accept sockets.

As I understand it, you are running varnish and backend webserver (say nginx or apache) on the very same linux machine, right?

First of all, try to run this command:

sudo netstat -anp | grep LISTEN | grep 8080

And see what process is bound on port 8080 and on which ip.

First part of your question suggests varnish is running, just not be able to connect to backend. But the second part tells me you are not able to start varnish. So please make it clear and perhaps attach output from the command above.

Let's continue with second part, ie varnish not able to start.

I guess you have backend server running on 8080, be it nginx, apache, whatever. Your varnish backend config confirms it after all.

Check that web server is bound on 127.0.0.1 and not on 0.0.0.0 not to allow public traffic to connect directly do backend web server.

If this is the case, you have to change listening ip:port of varnish to non-colliding combination.

You can either:

  • change port to something else as 8080, let's say 80
  • change port of backend web server to something else if you need 8080 to be public
  • double check your backend web server is listening on localhost only and bind varnish to your public ip instead of 0.0.0.0 (default, means all machine's ips)

You can do the last option by changing main varnish configuration to:

DAEMON_OPTS="-a 52.163.xxx.xx:8080 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"

This scenario has one important drawback. If you somehow come to new public ip, you have to change it in main varnish configuration too. If this is something you can encode into automation recipe, it shouldn't be problem. But if you manage it by hand, be sure you have really good documenting practice or you'll be hunting ghost bugs in future. :)

One mistake is having both Varnish and your backend server running on the same port 8080 . You have 2 options to solve this:

  1. Most straightforward and simple. Adjust Varnish DAEMON_OPTS to listen on port 80 .

  2. It may still work on the same ports, provided that you make Varnish and your backend server listen on different interfaces:

    • Varnish would normally listen on external interface. Thus, adjust your Varnish listen parameter to be bound to specific IP: DAEMON_OPTS="-a 52.163.xxx.xx:8080 ...
    • Bind your backend server (Apache, Nginx, whatever) to listen only on the loopback interface, 127.0.0.1 .

Your VCL is "empty" and you should be using corresponding plugin for Magento which will ensure that Varnish caches things, by generating correct VCL file for you:

  • Magento 1.x: Turpentine plugin
  • Magento 2.x: .. is able to generate VCL from admin backend of your Magento installation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM