R
R
Randewoo2019-06-09 01:10:10
Nginx
Randewoo, 2019-06-09 01:10:10

Error handling in Varnish?

Hello.
I saw that on some sites (like CloudFlare) Varnish serves as an error handler (404, 503, etc).
Here is my Varnish config:

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

sub vcl_synth {
    set resp.http.Content-Type = "text/html; charset=utf-8";
    set resp.http.Retry-After = "5";
    synthetic( {"<!DOCTYPE html>
    <html>
      <head>
        <title>"} + resp.status + " " + resp.reason + {"</title>
      </head>
      <body>
        <h1>Error "} + resp.status + " " + resp.reason + {"</h1>
        <p>"} + resp.reason + {"</p>
        <h3>Guru Meditation:</h3>
        <p>XID: "} + req.xid + {"</p>
        <hr>
        <p>Varnish cache server</p>
      </body>
    </html>
    "} );
    return (deliver);
}


nginx config:
spoiler
server {
    server_name cdn.site.me;
 		listen 443 ssl http2;

    location = / {
          proxy_http_version 1.1;
          proxy_pass http://127.0.0.1:80;
          proxy_set_header X-Real-IP  $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto https;
          proxy_set_header X-Forwarded-Port 443;
          proxy_set_header Host $host;
      }
  }
  server {
    server_name cdn.site.me;
  		listen 8080;
  
    root /var/www/html;
    index index.lua;
  
    location = / {
      content_by_lua_file /var/www/html/index.luac;
      lua_code_cache on;
    }
  }


And, in fact, when I go, for example, to cdn.site.me/324, nginx itself gives a 404 error, but I would like Varnish to give an error.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question