我試圖讓我的頭緩存圖像爲我的開放源代碼圖像託管serivce PictShare。在nginx反向代理的所有文件夾級別緩存圖像
Pictshare有一個智能查詢系統,上傳的圖像可以在「虛擬子目錄」中更改圖像。例如,這是鏈接到上傳的計算器標誌:https://www.pictshare.net/300/6cb55fe938.png
因爲我處理了很多流量:https://www.pictshare.net/6cb55fe938.png
我可以通過圖像名稱前添加/300/
到URL調整到300寬最近我希望我的nginx代理能夠從所有虛擬子文件夾中緩存所有圖像,但它不起作用。我讀過很多文章和很多stackoverflow的帖子,但沒有解決方案爲我工作。
到目前爲止,這是我的虛擬主機生產文件
proxy_cache_path /etc/nginx/cache/pictshare levels=1:2 keys_zone=pictshare:50m max_size=1000m inactive=30d;
proxy_temp_path /etc/nginx/tmp 1 2;
proxy_cache_key "$scheme$request_method$host$request_uri";
proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";
proxy_buffering on;
server {
...
location/{
proxy_pass http://otherserver/pictshare/;
include /etc/nginx/proxy_params;
location ~* \.(?:jpg|jpeg|gif|png|ico)$ {
expires max;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_valid 200 301 302 1y;
proxy_cache pictshare;
proxy_pass http://otherserver/pictshare$request_uri;
}
}
}
的問題是,沒有文件緩存,我看到了代理目的地每個圖像的要求。
我就開始工作的唯一途徑是通過增加一個特殊的位置到具有緩存明確啓用主機文件:
location /cached {
proxy_cache_valid 200 1y;
proxy_cache pictshare;
expires 1y;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
include /etc/nginx/proxy_params;
proxy_pass http://otherserver/pictshare/thumbs/;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
}
這個解決方案的明顯的問題是,圖像僅在緩存要求與/cached
如開始:https://www.pictshare.net/cached/6cb55fe938.png
添加緩存命令到根目錄下沒有選擇我,因爲我不想在形式和頁面進行高速緩存,只是圖像
哪裏是我的錯誤?
我們是人,不會是你寫的兩行解釋什麼是錯的OP的代碼和爲什麼你應該更好地工作? – phaberest
評論...是不是沒人花時間:) –
你快樂嗎? :D – Yura