Loading... ## 使用 Nginx 反向代理 ### Docker Hub 反向代理部分参考配置: ``` location / { proxy_pass https://registry-1.docker.io/; proxy_set_header Host registry-1.docker.io; 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 $scheme; proxy_buffering off; proxy_set_header Authorization $http_authorization; proxy_pass_header Authorization; proxy_intercept_errors on; recursive_error_pages on; error_page 301 302 307 = @handle_redirect; error_page 404 = @handle_page_not_found; } location @handle_redirect { resolver 8.8.8.8; set $saved_redirect_location '$upstream_http_location'; proxy_pass $saved_redirect_location; } location @handle_page_not_found { return 301 https://www.baidu.com; } ``` ### gcr.io 和 Docker Hub 不同的是,pull 时会先请求 gcr.io 获取一个 token,所以在反代配置中需要修改 `Www-Authenticate` 头信息: ``` location / { proxy_pass https://gcr.io; proxy_set_header Host gcr.io; 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 $scheme; proxy_buffering off; proxy_set_header Authorization $http_authorization; proxy_pass_header Authorization; proxy_hide_header Www-Authenticate; add_header Www-Authenticate 'Bearer realm="https://反代站点的域名/v2/token",service="gcr.io"'; proxy_intercept_errors on; recursive_error_pages on; error_page 301 302 307 = @handle_redirect; error_page 404 = @handle_page_not_found; } location @handle_redirect { resolver 8.8.8.8; set $saved_redirect_location '$upstream_http_location'; proxy_pass $saved_redirect_location; } location @handle_page_not_found { return 301 https://www.baidu.com; } ``` ## 参考资料 https://back.pub/post/docker-mirror-by-caddy/ 最后修改:2024 年 08 月 08 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏