您的位置:首页 > 运维架构 > Nginx

Nginx 实现本地静态文件内存缓存

2014-10-14 10:52 369 查看
1、需求
4000
背景

搭建静态文件服务器,要求在本地部署Nginx,访问静态文件时使用Nginx做内存缓存。

2、Nginx架构



3、nginx.conf

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;
server_tokens off;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

proxy_temp_path /dev/shm/temp_dir/;
proxy_cache_path /dev/shm/cache/ levels=1:2 keys_zone=cache_one:10m;

upstream local_img {
server localhost:81;
}
server{
listen 81;
server_name 127.0.0.1;
location / {
root /home/static/data/;
client_max_body_size 10m;
access_log off;
autoindex off;
}
}
server {
listen 80;
server_name img.test.com;
proxy_cache cache_one;
location / {
proxy_redirect off;
proxy_cache_valid 200 304 12h;
proxy_cache_valid 301 302 1m;
proxy_cache_valid any 1m;
proxy_cache_key $host$uri$is_args$args;
add_header X-Cache $upstream_cache_status;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://local_img; access_log off;
}
}

}
4、配置说明

proxy_cache缓存路径在/dev/shm下面,该目录为物理内存地址
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: