
我需要設定一個 HTTP 反向代理,它將能夠快取對上游伺服器的請求。
上游伺服器僅提供靜態檔案。
我面臨的問題是,我需要一個能夠盡快啟動第一個位元組的代理(它不能等待整個請求緩衝),同時仍然進行快取。這是因為我的檔案可能非常大(幾百兆位元組),但應用程式要求具有快速回應時間。
我嘗試使用 nginx,但是當我停用 proxy_buffering 時,它會完全停止快取。
是否有任何廣泛可用的、經過良好測試的開源專案可以做到這一點?漆?烏賊? HAProxy?
答案1
清漆將有利於這項工作:
sub vcl_backend_response {
# ...
# Large static files are delivered directly to the end-user without
# waiting for Varnish to fully read the file first.
# Varnish 4 fully supports Streaming, so use streaming here to avoid locking.
if (bereq.url ~ "^[^?]*\.(mp[34]|rar|rpm|tar|tgz|gz|wav|zip|bz2|xz|7z|avi|mov|ogm|mpe?g|mk[av]|webm)(\?.*)?$") {
unset beresp.http.set-cookie;
set beresp.do_stream = true;
set beresp.do_gzip = false; # Don't try to compress it for storage
}
# ...
}
答案2
您可以設定兩台 nginx 伺服器,一台啟用 proxy_buffering,另一台將快取來自上游的回應。