Get the App
SLTechnology News&Howtos  ›  Servers  › 

Varnish implements cache acceleration

Shulou Source: shulou.com Published: 2022-06-02 20:03:21 10月01日 Update

Varnish implements cache acceleration

1. Using varnish to implement cache acceleration for nginx

1. Experimental environment:

(1) one varnish cache server and one nginx server

(2) turn off the firewall and selinux

two。 Configure varnish

(1) modify the varnish configuration file:

Create a directory: mkdir-pv / data/varnish/cache modify owner: chown varnish.varnish / data/varnish/cache

(2) Test:

Second, varnish realizes the separation of dynamic and static.

(1) varnish configuration:

(2) Test:

(3) set multiple groups in the attachment content and do the load:

Example: import directors backend imgsrv1 {.host = "192.168.10.11"; .port = "80";} backend imgsrv2 {.host = "192.168.10.12"; .port = "80";} backend appsrv1 {.host = "192.168.10.21"; .port = "80" } backend appsrv2 {.host = "192.168.10.22"; .port = "80";} sub vcl_init {new imgsrvs = directors.random (); imgsrvs.add_backend (imgsrv1,10); imgsrvs.add_backend (imgsrv2,20); new staticsrvs = directors.round_robin (); appsrvs.add_backend (appsrv1); appsrvs.add_backend (appsrv2) New appsrvs = directors.hash (); appsrvs.add_backend (appsrv1,1); appsrvs.add_backend (appsrv2,1);} sub vcl_recv {if (req.url ~ "(? I)\. (css | js) $" {set req.backend_hint = staticsrvs.backend () } if (req.url ~ "(?)\. (jpg | jpeg | png | gif) $" {set req.backend_hint = imgsrvs.backend ();} else {set req.backend_hint = appsrvs.backend (req.http.cookie);}}

Security Inspection:

.probe: define the health status detection method; .url: the URL to be requested when testing. Default is "/"; .request: the specific request issued. .request = "GET / .healthtest.html HTTP/1.1", "Host: www.ww.com", "Connection: close" .window: judge its health status based on the number of recent checks Threshold: among the most recent checks defined in .window, the number of times defined by threshold hhold is successful; success threshold; .interval: detection frequency; .timeout: timeout; .timeout: expected response code. Default is 200. Configuration of health status detection: probe PB_NAME {} backend NAME = {.probe = PB_NAME;.}

Tags: Detection configuration cache health status success server service check test security content movement multiple security detection file method method duration number of times Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Tech Info Apple Microsoft Shulou Information