next door Phenolphthalein The boss complained to me that the blog avatar could not be loaded, and asked me to think of a way to do it quickly. See the following figure for details.

Boy, I haven't noticed because of the daily proxy. Qingguang cache looks at its own.

Yes, it is a serious problem that must be solved.

After pondering and testing, the collapse of the avatar is simply the reason why Gravatar's service is not working well in China. Therefore, this problem can be solved by using the domestic public CDN service, or building one yourself and replacing the original link in the Typecho program.

Replace old link

In the blog root directory /var/Typecho/Common.php In, use VSCODE or other editors, shortcut keys Ctrl+F search secure.gravatar.com The location of Typecho may be different due to different versions. My version is on line 991 or so.

 $url = $isSecure ? ' https://secure.gravatar.com ' : ' http://www.gravatar.com '; $url .= '/ avatar/';

Public CDNs available under search

Replace the link in the first line

 $url = $isSecure ? ' https://sdn.geekzu.org/avatar/ ' : ' https://cdn.v2ex.com/gravatar/ ';

Because the CDN link above already contains /avatar/ So you need to comment out this line or delete it directly.

 //$url .= '/ avatar/';

Then save, refresh, and everything returns to normal.

But what if the Typecho is updated and overwritten? Another method is to configure the program in the blog root directory config.inc.php Insert a paragraph at the end:

 /**Custom avatar source*/ define('__TYPECHO_GRAVATAR_PREFIX__', ' https://cdn.v2ex.com/gravatar/ ');

Generally, this configuration file will not be moved, so it is the most one-time method Recommended This method.

Take the place of yourself

It is OK to directly open a secondary domain name for reverse generation, but it is OK to use a secondary directory (such as himiku.com/avatar/ )It's also good to come to the counter generation. Reference 「 Gravatar image resources and Nginx reverse generation tutorial "I tried it myself.

Add a cache at the beginning of the configuration. After all, caching is fast and can save money. For example, put the cache in /home/wwwcache/gravatar

 proxy_cache_path /home/wwwcache/gravatar levels=1:2 keys_zone=gravatar:5m inactive=30m max_size=50m;

Then server Add a counter generation in the paragraph. For example, I want to use https://www.himiku.com/avatar/ , to directly reverse https://secure.gravatar.com/avatar/

 location /avatar/ { proxy_pass  https://secure.gravatar.com/avatar/ ; proxy_redirect off; proxy_set_header Host secure.gravatar.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Accept-Encoding ""; proxy_cache gravatar; proxy_cache_key $scheme$host$request_uri; proxy_cache_valid 200 304 3h; proxy_cache_valid 301 24h; proxy_cache_valid 500 502 503 504 0s; proxy_cache_valid any 3h; }

Do not like to use avatar , use instead touxiang OK, put the first line location /avatar/ Change to location /touxiang/ Just fine.

The more complete ones are roughly as follows.

 proxy_cache_path /home/wwwcache/gravatar levels=1:2 keys_zone=gravatar:5m inactive=30m max_size=50m; server { listen 80; server_name himiku.com ; return 301  https://himiku.com $request_uri; } server { listen 443 ssl http2; server_name himiku.com; index index.html; ssl........  ellipsis location /avatar/ { proxy_pass  https://secure.gravatar.com/avatar/ ; proxy_redirect off; proxy_set_header Host secure.gravatar.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header Accept-Encoding ""; proxy_cache gravatar; proxy_cache_key $scheme$host$request_uri; proxy_cache_valid 200 304 3h; proxy_cache_valid 301 24h; proxy_cache_valid 500 502 503 504 0s; proxy_cache_valid any 3h; } ...... Other Omissions }

Repeat the previous step and replace your own link.

If you want to use my anti proxy service, you can click the avatar in the comment area to get the link. However, long-term stability is not guaranteed. Ready to stop the service, please switch to the public cdn if you see it!