Business requirements Nginx Cache back-end tomcat (static files) to reduce stress on backend servers
# nginx-1.6.2.tar.gz Ngx_cache_purge-2.3.tar.gz
#编译安装
./configure--add-module=. /ngx_cache_purge-2.3--prefix=/usr/local/nginx--pid-path=/var/run/nginx/nginx.pid--lock-path=/var/lock/ Nginx.lock--user=nginx--group=nginx--with-http_ssl_module--with-http_gzip_static_module--with-http_stub_status _module
Make && make install
#安装ngx_cache_purge后 must restart Nginx to take effect (reload invalid error unknown directive "Proxy_cache_purge")
1 #定义缓存目录 2 proxy_temp_path /data/proxy_temp_dir; 3 Proxy_cache_path /data/proxy_cache_dir levels=1:2 keys_zone=cache_one:200m INACTIVE=1D max_size=30g;
1 #虚拟主机中配置 student.conf2 3 server {4Listen the;5 server_name student.metasequoia.com;6 7access_log/var/log/nginx/Student_access.log Cache;8error_log/var/log/nginx/Student_error.log;9 TenLocation ~/purge (/.*# (the test must be written on the location above otherwise the refresh is unsuccessful why) One { AAllow ip;# (written in 127.0.0. 1 o'clock test does not take effect why) (So write to host IP) - deny all; -Proxy_cache_purge Cache_one $host $1$is _args$args; the } - -Location ~. *\. (gif|jpg|jpeg|png|bmp|ico|js|CSS) $ { - Proxy_cache Cache_one; +Proxy_cache_valid $ 30412h; - proxy_cache_key $host $uri$is_args$args; + #expires 30d; AAdd_header xCache $upstream _cache_status; at -include/usr/local/nginx/vhost/proxy.configure; -Proxy_pass http://Student_server; - } - -Location/ { ininclude/usr/local/nginx/vhost/proxy.configure; -Proxy_pass http://Student_server; to } + -
1 #定义日志2Log_format Cache'$remote _addr [$time _local] "$request"'3 '"$upstream _status" $body _bytes_sent "$http _referer"'4 '"$http _user_agent"'5 '"$upstream _addr" "$upstream _response_time" $upstream _cache_status'; # $upstream _cache_status defines the cache status in the browser hit MISS EXPIRED
#example
Http://student.metasequoia.com/resource/images/login13.png
Clear Cache
Curl Student.fclassroom.com/purge/resource/images/login13.png
Nginx Add Proxy_cache module as cache server