The principle of building image caching mechanism is to reduce the burden of database and speed up the response of static resources.
Steps:
1.
Vim/usr/local/nginx/conf/nginx.conf
2.
http{. #设置Web缓存区名称为cache_one, the memory cache space size is 200mb,1 days without access to the content is automatically cleared, the hard disk cache space size is 30GB Proxy_cache_path/var/imgcache Test levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;}
Where/var/imgcachetest is the mkdir image cache directory.
3.
server{. Location/{Proxy_cache cache_one; Proxy_cache_valid 304 12h; #以域名, URI, parameters combined into the Web cache key value, Nginx based on the key value hash, storage cache content to the level two cache directory Proxy_cache_key $host $uri$is_args$args; Proxy_set_header Host $host; Proxy_set_header x-forwarded-for $remote _addr; Proxy_pass http://127.0.0.1:8080; Expires 1d; }e}
4. When you access the test picture, a picture cache is generated in the/var/imgcachetest directory, complete.
This article from "The day will be down to the great people also" blog, please be sure to keep this source http://19940428.blog.51cto.com/13352428/1972152
Nginx+proxy_cache Picture Cache