配置nginx缓存存放在内存中
方法一:
1、修改/etc/fstab挂接内存文件系统,并指定selinux context
tmpfs /var/tmp/nginx/proxy_cache tmpfs defaults,size=100m,context=system_u:object_r:httpd_cache_t:s0
tmpfs /var/tmp/nginx/proxy_temp tmpfs defaults,size=100m,context=system_u:object_r:httpd_cache_t:s0
然后
mkdir -p /var/tmp/nginx/proxy_cache
mount -t ramfs none /var/tmp/nginx/proxy_cache
mkdir -p /var/tmp/nginx/proxy_temp
mount -t ramfs none /var/tmp/nginx/proxy_temp
2. 在http中指定nginx的proxy_temp_path
proxy_temp_path /var/tmp/nginx/proxy_temp ;
proxy_cache_path /var/tmp/nginx/proxy_cache levels=1:2 keys_zone=cache_one:64m inactive=1d max_size=128m;
add_header X-Cache HIT-LT;
上述方法适合于xen linux VPS和独立主机
方法二:
新建缓存存放地址
mkdir /dev/shm/proxy_cachechmod 1777 /dev/shm/proxy_cache
mkdir -p /var/tmp/nginx/proxy_cache
mount --bind /dev/shm/proxy_cache /var/tmp/nginx/proxy_cache
mkdir /dev/shm/proxy_temp
chmod 1777 /dev/shm/proxy_temp
mkdir -p /var/tmp/nginx/proxy_temp
mount --bind /dev/shm/proxy_temp /var/tmp/nginx/proxy_temp
在nginx主配置文件添加下面语句
proxy_temp_path /var/tmp/nginx/proxy_temp ;
proxy_cache_path /var/tmp/nginx/proxy_cache levels=1:2 keys_zone=cache_one:64m inactive=1d max_size=128m;
add_header X-Cache HIT-LT;
方法二适合于openvz linux VPS且要根据openvz VPS 下/proc/user_beancounters 下shmpages行的barrier 值确定proxy_cache_path的 max_size值,
备注:
nginx缓存需要版本高于0.7.48才支持。