halo 豆瓣 插件 plugin-douban 反代豆瓣图片

编辑 / 发布于2025-08-12 / 更新于2025-08-12 / 阅读 4

Nginx 配置

发现 /douban 页面加载不了图片,查了下需要对豆瓣图片进行代理。源文档中只有nginx的代理方法

location ^~ / {
    proxy_pass https://img9.doubanio.com; 
    proxy_set_header Host img9.doubanio.com; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header Referer img9.doubanio.com; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header REMOTE-HOST $remote_addr; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
    proxy_set_header X-Forwarded-Proto $scheme; 
    proxy_http_version 1.1; 
    add_header X-Cache $upstream_cache_status; 
    add_header Strict-Transport-Security "max-age=31536000"; 
    add_header Cache-Control no-cache; 
}

Caddy 路由重定向配置

自己用的caddy,改了一个caddy的豆瓣图片反代的配置文件

访问 域名/doubanproxy/图片路径 ,会将他重写成 域名/图片路径,然后到豆瓣。

这样可以和博客共用一个域名。

填写插件的 代理地址 https://yourdomain.com/doubanproxy

yourdomain.com {
    @douban path_regexp douban ^/doubanproxy/(.*)$
    route @douban {
        rewrite * /{http.regexp.douban.1}
        reverse_proxy https://img9.doubanio.com {
            header_up Host "img9.doubanio.com"
            header_up X-Real-IP {remote_host}
            header_up Referer " https://img9.doubanio.com"
            header_up X-Forwarded-For {remote_host}
            header_up REMOTE-HOST {remote_host}
            header_up Upgrade {http.request.header.Upgrade}
            header_up Connection "upgrade"
            header_up X-Forwarded-Proto {scheme}
            transport http {
                versions h1 h2
            }
        }
    }
    reverse_proxy xxx:xxx
}

Caddy 直接配置

或者也可以直接新建一个域名配置反代(未测试)

yourdomain.com {
    reverse_proxy https://img9.doubanio.com {
        header_up Host "img9.doubanio.com"
        header_up X-Real-IP {remote_host}
        header_up Referer " https://img9.doubanio.com"
        header_up X-Forwarded-For {remote_host}
        header_up REMOTE-HOST {remote_host}
        header_up Upgrade {http.request.header.Upgrade}
        header_up Connection "upgrade"
        header_up X-Forwarded-Proto {scheme}
        transport http {
            versions h1 h2
        }
    }
}