首頁 >後端開發 >php教程 >nginx作為圖片瀏覽前端cache設定範例

nginx作為圖片瀏覽前端cache設定範例

WBOY
WBOY原創
2016-08-08 09:28:081103瀏覽
#图片浏览cache
proxy_cache_path /var/cache/nginx/imgCache levels=2:2:2 keys_zone=imgCache:256m inactive=7d max_size=0m;
server
{
    listen 80;
    server_name img.xxxx.net;
    root /data/www/;

    location ~ \.(jpg|jpeg|jp2|png|gif|bmp|ico|wbmp|xbm|tiff)(/\d*)?(/\d*)?(\?.*)?$ {
        proxy_pass  http://127.0.0.1:8118;
        proxy_cache imgCache;
        proxy_cache_key $host$uri;
        proxy_set_header host inner.img.xxxx.com;
        proxy_cache_valid  200 30d;
        proxy_cache_valid any 1m;
        expires 30d;
    }

    access_log  /var/log/nginx/img_cache.log main;
    error_log   /var/log/nginx/img_cache.log.err debug;
}
server
{
    listen 8118;
    server_name inner.img.xxxx.net;
    root /data/www/;

    location ~ \.(jpg|jpeg|jp2|png|gif|bmp|ico|wbmp|xbm|tiff)(/\d*)?(/\d*)?(\?.*)?$ {
        fastcgi_pass  unix:/var/run/php-cgi.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
        rewrite ^/(.*)$ /app/image/index.php?mod=download break;
        expires 7d;
    }

    access_log  /var/log/nginx/img_download.log main;
    error_log   /var/log/nginx/img_download.log.err debug;
}

以上就介紹了nginx作為圖片瀏覽前端cache配置範例,包含了方面的內容,希望對PHP教學有興趣的朋友有所幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn