```apache # 静态默认图 location /static/ { alias /xxxx/; expires 30d; access_log off; error_log off; } # 主入口:拦截任何 default=http... 或 default=https%3A%2F%2F… location ^~ /avatar/ { resolver 8.8.8.8 1.1.1.1 valid=300s; # 如果用户给了 default=http 或 default=https%3A%2F%2F,直接返回本地默认图 if ($args ~* "(^|&)(default=https?://|default=https%3A%2F%2F)") { rewrite ^ /static/default.jpg last; } # —— 下面保持原有代理 & fallback 逻辑 —— proxy_pass https://secure.gravatar.com$uri$is_args$args; proxy_ssl_server_name on; 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_cache cache_one; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 304 301 302 43200m; proxy_ignore_headers Set-Cookie Cache-Control Expires; add_header X-Cache $upstream_cache_status; proxy_intercept_errors on; error_page 403 444 502 504 404 = @fallback1; } location @fallback1 { proxy_pass https://gravatar.loli.net$uri$is_args$args; proxy_ssl_server_name on; proxy_set_header Host gravatar.loli.net; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache cache_one; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 304 301 302 43200m; proxy_ignore_headers Set-Cookie Cache-Control Expires; add_header X-Cache $upstream_cache_status; proxy_intercept_errors on; error_page 403 444 502 504 404 = @fallback2; } location @fallback2 { proxy_pass https://cn.gravatar.com$uri$is_args$args; proxy_ssl_server_name on; proxy_set_header Host cn.gravatar.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache cache_one; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 304 301 302 43200m; proxy_ignore_headers Set-Cookie Cache-Control Expires; add_header X-Cache $upstream_cache_status; proxy_intercept_errors on; error_page 403 444 502 504 404 = @fallback3; } location @fallback3 { proxy_pass https://cdn.v2ex.com/gravatar$uri$is_args$args; proxy_ssl_server_name on; proxy_set_header Host cdn.v2ex.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache cache_one; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 304 301 302 43200m; proxy_ignore_headers Set-Cookie Cache-Control Expires; add_header X-Cache $upstream_cache_status; # 最终失败,直接落到本地默认图 proxy_intercept_errors on; error_page 403 444 502 504 404 = /static/default.jpg; } # 拒绝其它一切路径 location / { return 403; } ``` ```js // @name Gravatar 替換為自定義地址 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 將所有 gravatar.com 替換為你指定的加速服務 // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; const observer = new MutationObserver(() => { document.querySelectorAll('img[src*="gravatar.com/avatar"], img[src*="secure.gravatar.com/avatar"]').forEach(img => { img.src = img.src .replace('https://secure.gravatar.com/avatar/', 'https://填入自己的反向代理地址/avatar/') .replace('https://www.gravatar.com/avatar/', 'https://填入自己的反向代理地址/avatar/'); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); ``` Loading... ```apache # 静态默认图 location /static/ { alias /xxxx/; expires 30d; access_log off; error_log off; } # 主入口:拦截任何 default=http... 或 default=https%3A%2F%2F… location ^~ /avatar/ { resolver 8.8.8.8 1.1.1.1 valid=300s; # 如果用户给了 default=http 或 default=https%3A%2F%2F,直接返回本地默认图 if ($args ~* "(^|&)(default=https?://|default=https%3A%2F%2F)") { rewrite ^ /static/default.jpg last; } # —— 下面保持原有代理 & fallback 逻辑 —— proxy_pass https://secure.gravatar.com$uri$is_args$args; proxy_ssl_server_name on; 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_cache cache_one; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 304 301 302 43200m; proxy_ignore_headers Set-Cookie Cache-Control Expires; add_header X-Cache $upstream_cache_status; proxy_intercept_errors on; error_page 403 444 502 504 404 = @fallback1; } location @fallback1 { proxy_pass https://gravatar.loli.net$uri$is_args$args; proxy_ssl_server_name on; proxy_set_header Host gravatar.loli.net; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache cache_one; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 304 301 302 43200m; proxy_ignore_headers Set-Cookie Cache-Control Expires; add_header X-Cache $upstream_cache_status; proxy_intercept_errors on; error_page 403 444 502 504 404 = @fallback2; } location @fallback2 { proxy_pass https://cn.gravatar.com$uri$is_args$args; proxy_ssl_server_name on; proxy_set_header Host cn.gravatar.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache cache_one; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 304 301 302 43200m; proxy_ignore_headers Set-Cookie Cache-Control Expires; add_header X-Cache $upstream_cache_status; proxy_intercept_errors on; error_page 403 444 502 504 404 = @fallback3; } location @fallback3 { proxy_pass https://cdn.v2ex.com/gravatar$uri$is_args$args; proxy_ssl_server_name on; proxy_set_header Host cdn.v2ex.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_cache cache_one; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 304 301 302 43200m; proxy_ignore_headers Set-Cookie Cache-Control Expires; add_header X-Cache $upstream_cache_status; # 最终失败,直接落到本地默认图 proxy_intercept_errors on; error_page 403 444 502 504 404 = /static/default.jpg; } # 拒绝其它一切路径 location / { return 403; } ``` ```js // @name Gravatar 替換為自定義地址 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 將所有 gravatar.com 替換為你指定的加速服務 // @match *://*/* // @grant none // ==/UserScript== (function() { 'use strict'; const observer = new MutationObserver(() => { document.querySelectorAll('img[src*="gravatar.com/avatar"], img[src*="secure.gravatar.com/avatar"]').forEach(img => { img.src = img.src .replace('https://secure.gravatar.com/avatar/', 'https://填入自己的反向代理地址/avatar/') .replace('https://www.gravatar.com/avatar/', 'https://填入自己的反向代理地址/avatar/'); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); ``` 最后修改:2025-07-21 © 允許規範轉載 讚賞 讚賞作者 赞 如果觉得我的文章对你有用,请随意赞赏