Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # systemd service (with multiple ports for testing)
- [Unit]
- Description=Varnish HTTP accelerator
- Documentation=https://www.varnish-cache.org/docs/6.1/ man:varnishd
- [Service]
- Type=simple
- Restart=always
- LimitNOFILE=131072
- LimitMEMLOCK=82000
- ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -a :8000 -a :8001 -a :8002 -a :8003 -a :8004 -a :8005 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,14g
- ExecReload=/usr/share/varnish/varnishreload
- ProtectSystem=full
- ProtectHome=true
- PrivateTmp=true
- PrivateDevices=true
- [Install]
- WantedBy=multi-user.target
- # Varnish VCL configuration
- vcl 4.0;
- import directors; # load the directors
- # Default backend definition. Set this to point to your content server.
- backend nlp1 {
- .host = "nlp1";
- .host_header = "nlp1";
- .probe = {
- .url = "/status";
- .timeout = 1s;
- .interval = 5s;
- .window = 5;
- .threshold = 3;
- }
- }
- backend nlp2 {
- .host = "nlp2";
- .host_header = "nlp2";
- .probe = {
- .url = "/status";
- .timeout = 1s;
- .interval = 5s;
- .window = 5;
- .threshold = 3;
- }
- }
- backend nlp3 {
- .host = "nlp3";
- .host_header = "nlp3";
- .probe = {
- .url = "/status";
- .timeout = 1s;
- .interval = 5s;
- .window = 5;
- .threshold = 3;
- }
- }
- backend nlp4 {
- .host = "nlp4";
- .host_header = "nlp4";
- .probe = {
- .url = "/status";
- .timeout = 1s;
- .interval = 5s;
- .window = 5;
- .threshold = 3;
- }
- }
- backend nlp5 {
- .host = "nlp5";
- .host_header = "nlp5";
- .probe = {
- .url = "/status";
- .timeout = 1s;
- .interval = 5s;
- .window = 5;
- .threshold = 3;
- }
- }
- backend nlp6 {
- .host = "nlp6";
- .host_header = "nlp6";
- .probe = {
- .url = "/status";
- .timeout = 1s;
- .interval = 5s;
- .window = 5;
- .threshold = 3;
- }
- }
- sub vcl_init {
- new nlp_vdir = directors.round_robin();
- nlp_vdir.add_backend(nlp1);
- nlp_vdir.add_backend(nlp2);
- nlp_vdir.add_backend(nlp3);
- nlp_vdir.add_backend(nlp4);
- nlp_vdir.add_backend(nlp5);
- nlp_vdir.add_backend(nlp6);
- }
- sub vcl_recv {
- # Happens before we check if we have this in cache already.
- #
- # Typically you clean up the request here, removing cookies you don't need,
- # rewriting the request, etc.
- # Set backend
- set req.backend_hint = nlp_vdir.backend();
- # Pass if X-No-Cache is set
- if (req.http.X-No-Cache){
- return(pass);
- }
- # Unset cookies
- unset req.http.Cookie;
- }
- sub vcl_backend_fetch {
- # Use host defined in backend
- unset bereq.http.host;
- return(fetch);
- }
- sub vcl_backend_response {
- # Happens after we have read the response headers from the backend.
- #
- # Here you clean the response headers, removing silly Set-Cookie headers
- # and other mistakes your backend does.
- unset beresp.http.Set-Cookie;
- // Set TTL if request that should be cached and status code is 2xx, 3xx or 4xx
- if (
- beresp.status >= 200 && beresp.status < 500
- && beresp.http.Cache-Control !~ "no-cache"
- ){
- set beresp.ttl = 1w;
- }
- else {
- set beresp.ttl = 0s;
- }
- }
- sub vcl_deliver {
- # Happens when we have all the pieces we need, and are about to send the
- # response to the client.
- #
- # You can do accounting or modifying the final object here.
- if (obj.hits > 0){
- set resp.http.X-Cache = "HIT";
- }
- else {
- set resp.http.X-Cache = "MISS";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement