Nginx 实现本地静态文件内存缓存
2014-10-14 10:52
369 查看
1、需求
4000
背景
搭建静态文件服务器,要求在本地部署Nginx,访问静态文件时使用Nginx做内存缓存。
2、Nginx架构
![](https://oscdn.geek-share.com/Uploads/Images/Content/202009/28/77efe988b2ed96982c48c5cddfb56b98)
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下面,该目录为物理内存地址
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下面,该目录为物理内存地址
相关文章推荐
- nginx实现动态/静态文件缓存-技术流ken
- Nginx使用Proxy_cache实现服务器端静态文件缓存
- PHP实现文件缓存转化内存缓存
- Nginx 巧用Linux内存加速静态文件访问
- 缓存nginx服务器的静态文件
- 用Nginx做反向代理并缓存静态文件
- Linux下nginx支持.htaccess文件实现伪静态的方法!
- Linux下nginx支持.htaccess文件实现伪静态的方法!
- Centos下让nginx支持.htaccess文件实现伪静态的方法!
- nginx 设置本地浏览器缓存文件,nginx gzip压缩
- Centos下让nginx支持.htaccess文件实现伪静态的方法!
- Nginx对于图片,js等静态文件的缓存设置
- Linux下nginx支持.htaccess文件实现伪静态的方法!
- Linux下nginx支持.htaccess文件实现伪静态的方法!
- Nginx 下缓存静态文件(如css js)
- 304 静态文件本地缓存
- nginx 静态文件缓存
- PHP实现文件缓存转内存缓存
- (转)Linux下nginx支持.htaccess文件实现伪静态的方法!
- Linux下nginx支持.htaccess文件实现伪静态的方法!