Tuesday, 15 July 2014

optimization - Varnish, custom subroutine with early exit -


I am new in varnish while editing our backend selector sub-routine, I started my initial return pattern in varnish configuration files Discovered

  sub select_backend {if (req.http.host ~ "tracking ... ..") {set req.backend = tracking; } If (req.http.host ~ "myapp1.domain.com") {if (req.url ~ "^ / Asur / route") {Error 403 "Forbidden"; } Set req.backend = app1; } If (req.http.host ~ "myapp2.domain.com") {set req.backend = app2; }} Sub vcl_recv {// select other content_back; }  

Changing the backend twice without proper return / exit statement is a risk (as the file makes it more complicated). Is it possible to use early return patterns to avoid this? If not, how can I save the if / elseif pattern without a bad pattern?

There is currently no good way to do this, as explained:

VCL's "return" statement gives VCL control of return to varnish from state engine. If you define your own function and call it with the default functions, typing "return (FU)" will not return your custom function to the default function, but will return the performance from VCL to varnish. This is why we say that VCL has terminated the statement with traditional return values.

There are such needs and recommended:

  if (req .http.host ~ "tracking ... ..") { Set req.backend = tracking; } Elsf (req.http.host ~ "myapp1.domain.com") {if (req.url ~ "^ / Asur / route") {Error 403 "Forbidden"; } Set req.backend = app1; } Elsf (req.http.host ~ "myapp2.domain.com") {set req.backend = app2; }  

If you place the pattern, then there should be no opportunity to set two times supported twice ... .. Alsif . If you have different if {} blocks, you can do this.


No comments:

Post a Comment