Passing Backend App Errors to End Users

Kelvin Loke me at kelvinloke.com
Thu Jul 21 02:55:47 CEST 2016


>
> Varnish will do that by default. If you get a 503 from Varnish, it is
> because your VCL returns that or because your backend violates the HTTP
> protocol.
>
> As always: Show us varnishlog and we will be able to tell.
>
> --
> Andreas
>

Thanks for responding, let me give you a live example so you can understand
clearer : )

1. User -> Backend (b.kelvinloke.com). Backend returns HTTP 400 with body
"Missing fromDate query string.", which is good.

2. User -> Varnish (v.kelvinloke.com) -> Backend. Varnish removes Backend's
error body, replace with Varnish's generic error body.

My goal is to make Varnish to show Backend's error body, not Varnish's
generic error body, which I have a difficult time to figure it out. I
actually tried below but Varnish doesn't allow me to reload the config,
with error "Running VCC-compiler failed, exited with 2" on resp.body
variable.

sub vcl_synth {
    if (resp.status == 400) {
set resp.body = {"<!DOCTYPE html>
<html>
 <head>
 </head>
 <body>
"} + resp.body + {"
 </body>
</html>
"};
return (deliver);
}
}

Here you go for the varnishlog if it helps.

-   Begin          bereq 34174473 pass
-   Timestamp      Start: 1469062408.399294 0.000000 0.000000
-   BereqMethod    GET
-   BereqURL       /
-   BereqProtocol  HTTP/1.1
-   BereqHeader    host: v.kelvinloke.com
-   BereqHeader    Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
-   BereqHeader    Accept-Language: en-US,en;q=0.8
-   BereqHeader    Cache-Control: no-cache
-   BereqHeader    Pragma: no-cache
-   BereqHeader    Upgrade-Insecure-Requests: 1
-   BereqHeader    User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
-   BereqHeader    X-Forwarded-Port: 80
-   BereqHeader    X-Forwarded-Proto: http
-   BereqHeader    X-Forwarded-For: 190.112.230.244, 172.31.1.229
-   BereqHeader    True-Client-IP: 190.112.230.244
-   BereqHeader    Accept-Encoding: gzip
-   BereqHeader    X-Varnish: 34174474
-   VCL_call       BACKEND_FETCH
-   VCL_return     fetch
-   BackendOpen    40 928d2c0c-8e82-4cdc-a194-b6ad0f14e051.kelvin
54.65.82.174 80 172.31.8.52 40796
-   BackendStart   54.65.82.174 80
-   Timestamp      Bereq: 1469062408.401388 0.002093 0.002093
-   Timestamp      Beresp: 1469062408.403494 0.004200 0.002107
-   BerespProtocol HTTP/1.1
-   BerespStatus   400
-   BerespReason   Bad Request
-   BerespHeader   Server: nginx/1.6.2
-   BerespHeader   Date: Thu, 21 Jul 2016 00:43:01 GMT
-   BerespHeader   Content-Type: text/html
-   BerespHeader   Content-Length: 31
-   BerespHeader   Connection: close
-   BerespHeader   ETag: "579014ce-1f"
-   TTL            RFC -1 10 -1 1469062408 1469062408 1469061781 0 0
-   VCL_call       BACKEND_RESPONSE
-   BerespUnset    ETag: "579014ce-1f"
-   TTL            VCL 120 10 0 1469062408
-   VCL_return     deliver
-   Storage        malloc Transient
-   ObjProtocol    HTTP/1.1
-   ObjStatus      400
-   ObjReason      Bad Request
-   ObjHeader      Server: nginx/1.6.2
-   ObjHeader      Date: Thu, 21 Jul 2016 00:43:01 GMT
-   ObjHeader      Content-Type: text/html
-   ObjHeader      Content-Length: 31
-   Fetch_Body     3 length stream
-   BackendClose   40 928d2c0c-8e82-4cdc-a194-b6ad0f14e051.kelvin
-   Timestamp      BerespBody: 1469062408.403543 0.004249 0.000049
-   Length         31
-   BereqAcct      528 0 528 171 31 202
-   End

*   << Request  >> 34174473
-   Begin          req 34174464 rxreq
-   Timestamp      Start: 1469062408.399251 0.000000 0.000000
-   Timestamp      Req: 1469062408.399251 0.000000 0.000000
-   ReqStart       172.31.1.229 32033
-   ReqMethod      GET
-   ReqURL         /
-   ReqProtocol    HTTP/1.1
-   ReqHeader      host: v.kelvinloke.com
-   ReqHeader      Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
-   ReqHeader      Accept-Encoding: gzip, deflate, sdch
-   ReqHeader      Accept-Language: en-US,en;q=0.8
-   ReqHeader      Cache-Control: no-cache
-   ReqHeader      Pragma: no-cache
-   ReqHeader      Upgrade-Insecure-Requests: 1
-   ReqHeader      User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
-   ReqHeader      X-Forwarded-For: 190.112.230.244
-   ReqHeader      X-Forwarded-Port: 80
-   ReqHeader      X-Forwarded-Proto: http
-   ReqHeader      Connection: keep-alive
-   ReqUnset       X-Forwarded-For: 190.112.230.244
-   ReqHeader      X-Forwarded-For: 190.112.230.244, 172.31.1.229
-   VCL_call       RECV
-   ReqHeader      True-Client-IP: 190.112.230.244
-   ReqUnset       Accept-Encoding: gzip, deflate, sdch
-   ReqHeader      Accept-Encoding: gzip
-   VCL_return     pass
-   VCL_call       HASH
-   VCL_return     lookup
-   VCL_call       PASS
-   VCL_return     fetch
-   Link           bereq 34174474 pass
-   Timestamp      Fetch: 1469062408.403541 0.004290 0.004290
-   RespProtocol   HTTP/1.1
-   RespStatus     400
-   RespReason     Bad Request
-   RespHeader     Server: nginx/1.6.2
-   RespHeader     Date: Thu, 21 Jul 2016 00:43:01 GMT
-   RespHeader     Content-Type: text/html
-   RespHeader     Content-Length: 31
-   RespHeader     X-Varnish: 34174473
-   RespHeader     Age: 0
-   RespHeader     Via: 1.1 varnish-v4
-   VCL_call       DELIVER
-   RespUnset      Via: 1.1 varnish-v4
-   RespUnset      Server: nginx/1.6.2
-   RespUnset      X-Varnish: 34174473
-   VCL_return     synth
-   Timestamp      Process: 1469062408.403549 0.004297 0.000008
-   Timestamp      Process: 1469062408.403551 0.004300 0.000002
-   RespHeader     Date: Thu, 21 Jul 2016 00:53:28 GMT
-   RespHeader     Server: Varnish
-   RespHeader     X-Varnish: 34174473
-   RespProtocol   HTTP/1.1
-   RespStatus     400
-   RespReason     Bad Request
-   RespReason     Bad Request
-   VCL_call       SYNTH
-   RespHeader     Content-Type: text/html; charset=utf-8
-   RespHeader     Retry-After: 5
-   VCL_return     deliver
-   RespHeader     Content-Length: 258
-   Storage        malloc Transient
-   Debug          "RES_MODE 2"
-   RespHeader     Connection: keep-alive
-   Timestamp      Resp: 1469062408.403587 0.004336 0.000036
-   ReqAcct        499 0 499 204 258 462
-   End
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20160721/80d471ca/attachment-0001.html>


More information about the varnish-misc mailing list