Background Image
Table of Contents Table of Contents
Previous Page  62 / 68 Next Page
Information
Show Menu
Previous Page 62 / 68 Next Page
Page Background

CODE/

VARNISH

62

REVISTA LOCAWEB

compressing these

remove req.http.

Accept-Encoding;

} elsif (req.http.

Accept-Encoding ~ "gzip") {

set req.http.Accept-

Encoding = "gzip";

} elsif (req.http.

Accept-Encoding ~ "deflate")

{

set req.http.Accept-

Encoding = "deflate";

} else {

# unknown algorithm

remove req.http.

Accept-Encoding;

}

}

# IF THIS IS A PURGE

REQUEST, THEN CHECK THE IPS

SET ABOVE

# BLOCK IF NOT ONE OF

THOSE IPS

# #######################

###########################

########

if (req.request ==

"PURGE") {

if ( !client.ip ~ purge

) {

error 405 "Not

allowed.";

}

return (lookup);

}

# PIPE ALL NON-STANDARD

REQUESTS

# #######################

###########################

########

if (req.request != "GET"

&&

req.request != "HEAD" &&

req.request != "PUT" &&

req.request != "POST" &&

req.request != "TRACE"

&&

req.request != "OPTIONS"

&&

req.request != "DELETE")

{

return (pipe);

}

# ONLY CACHE GET AND HEAD

REQUESTS

# ########################

###########################

#######

if (req.request != "GET"

&& req.request != "HEAD") {

return (pass);

}

# OPTIONAL: DO NOT CACHE

LOGGED IN USERS (THIS OCCURS

IN FETCH TO, EITHER

# COMMENT OR UNCOMMENT

BOTH

# #######################

###########################

########

if ( req.http.cookie ~

"wordpress_logged_in" ) {

return( pass );

}

# IF THE REQUEST IS NOT

FOR A PREVIEW, WP-ADMIN OR

WP-LOGIN

# THEN UNSET THE COOKIES

# ########################

###########################

#######

if (

!(req.url ~ "wp-

(login|admin)")

&& !(req.url ~

"&preview=true" )

){

unset req.http.cookie;

}

# IF BASIC AUTH IS ON THEN

DO NOT CACHE

# ########################

###########################

#######

if (req.http.Authorization

|| req.http.Cookie) {

return (pass);

}

# LIST URLS NOT TO BE

CACHED

# USUALLY THIS INCLUDES

THE PREVIEW QUERY STRING, A

NOCACHE

# QUERY STRING, AND FILES

THAT WILL BE SERVED BY THE

CDN

# SUCH AS IMAGES, CSS, AND

JS. IF YOU ARE NOT USING

A CDN

# YOU CAN CACHE YOUR

STATIC RESOURCES TOO

# #######################

###########################

########

if (

req.url ~ "preview"

|| req.url ~ "nocache"

|| req.url ~ "\.css$"

|| req.url ~ "\.js$"

|| req.url ~ "\.jpg$"

|| req.url ~ "\.jpeg$"

|| req.url ~ "\.gif$"

|| req.url ~ "\.png$"

) {

return (pass);

}

# IF YOU GET HERE THEN

THIS REQUEST SHOULD BE

CACHED

# #######################

###########################

Site oficial do PHP: linguagem trabalha facilmente com o Varnish