Some bloggers say that the Gravatar server cannot be accessed or is too slow, resulting in slow access to my website due to loading. So I will reverse proxy Gravatar. Nginx anti-generation is common, but it is not discussed in this chapter. Note: This chapter only applies to Varnish3. First, create backend as follows: backendavatarserver {. host
Some bloggers say that the Gravatar server cannot be accessed or is too slow, resulting in slow access to my website due to loading. So I will reverse proxy Gravatar. Nginx anti-generation is common, but it is not discussed in this chapter. Note: This chapter only applies to Varnish3. First, create backend as follows: backend avatarserver {. host =
Some bloggers say that the Gravatar server cannot be accessed or is too slow, resulting in slow access to my website due to loading.
So I will reverse proxy Gravatar. Nginx anti-generation is common, but it is not discussed in this chapter.
Note: This chapter only applies to Varnish3. First, create backend as follows:
backend avatarserver {
.host = "192.0.80.240";
.port = "80";
}
How does this 192.0.80.240 IP address come from?
It comes from dig gravatar.com. Gravatar has multiple IP addresses to achieve load balancing. However, Varnish3 only supports parsing one IP address:
backend avatarserver {
.host = "gravatar.com";
.port = "80";
}
Then, Varnish will prompt you to select an IP address, resulting in failure to start Varnish.
However, it is well known that Gravatar is the master server. Even the US server, Gravatar connection latency is less than 30 ms.
If you use a second-level domain name, such as www, 1, 2, 3, 4 ·, you can directly use the CDN service to obtain better and faster server response.
However, unfortunately, CDN recognizes domain names to determine whether you have the permission to parse them. CDN also has different IP addresses. Therefore, we cannot simply use the following two examples for parsing:
Backend avatarserver {
. Host = "www.gravatar.com ";
. Port = "80 ";
}
# When Varnish is started, the system prompts you to select an IP address, which fails.
Backend avatarserver {
. Host = "68.232.44.121 ";
. Port = "80 ";
}
# Start Varnish and the resolution is normal. What CDN obtains is that your domain name has resolved this IP address, and the service list of your CDN carrier does not exist. It will return 404 to you and fail.
Therefore, only one of the primary domain names can be selected as the Varnish reverse object. Fortunately, Gravatar allows direct IP Access, saving a lot of trouble.
Add the following in sub vcl_recv:
if (req.http.host ~ "^(avatar.kn007.net)$"){
if (req.http.REFERER ~ "kn007.net"){
set req.backend = avatarserver;
} else {
error 403 "Access Denied";
}
}
This is to determine whether the REFERER source is from the main domain name of our blog. If access is permitted, it is a anti-leech method.
Finally, set the cache expiration time in sub vcl_fetch, for example, one day?
set beresp.ttl = 24h
This completes Varnish's reverse generation of Gravatar.
How can I use Wordpress, or automatically replace the original Gravatar address as our reverse address?
You can use the Hook of WP to add the following code in functions. php. The regular expression is rough and easy to use.
function setting_get_avatar($avatar) {
$avatar = preg_replace("#(http|https):\/\/.*?\.gravatar.com#i","http://avatar.kn007.net",$avatar);
return $avatar;
}
add_filter( 'get_avatar', 'setting_get_avatar', 1 );
However, you have to ensure that get_avatar has not been hooked, or you have to change the priority or merge functions.
This is the end of teaching materials.
PS: Remind me again that my blog is about to reapply for an ICP filing. The website may be closed at any time. Thank you...
In addition, Google's Favicon has been added to the anti-proxy cache.
Reprinted please note