Chinaunix
标题:
nginx的缓存问题
[打印本页]
作者:
三里屯摇滚
时间:
2011-08-18 11:36
标题:
nginx的缓存问题
nginx的缓存问题
看过张宴先生的文章,使用nginx的proxy_cache取代squid , 然后试验了下,结果发现在缓存时,经常会出现数据缓存了一半的情况,不知道有人知道原因? 测试了nginx0.8.17 和nginx1.1.0 都有这个问题,难道是我配置文件写的有问题,贴出来, 大家帮忙看看。
nginx.conf:
user root;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
worker_rlimit_nofile 65500;
events {
worker_connections 65500;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user $time_local "$request_method http:
//$host$request_uri HTTP/1.1" $status $bytes_sent "$http_referer" "$http_user_ag
ent" TCP_HIT:NONE $request_time';
access_log logs/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 0;
#keepalive_timeout 65;
gzip on;
gzip_static on;
gzip_http_version 1.1;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_proxied any;
#gzip_comp_level 5;
#gzip_disable "MSIE [1-6]\.";
#gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server_names_hash_bucket_size 128;
proxy_temp_path /home/cache_nginx/temp;
proxy_cache_path /home/cache_nginx/cache levels=1:2 keys_zone=cache_one:500
m inactive=3d max_size=50g;
include ./david/*.conf;
}
./david/test.conf
upstream www.tt48.com {
server 192.168.1.56:80 fail_timeout=30s;
}
server {
listen 80;
# server_name 192.168.1.48;
index index.html index.htm index.php index.asp index.aspx index.jsp;
root /home/cache_nginx/cache;
location / {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one;
proxy_cache_valid 200 304 20m;
proxy_cache_valid any 5m;
proxy_cache_key $host$uri;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://www.tt48.com;
add_header X-cache "$upstream_cache_status from gen";
}
location ~ .*\? {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://www.tt48.com;
add_header X-cache "$upstream_cache_status from wenhao";
}
location ~ .*\.(jsp|asp|asps|php|do|action)$ {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://www.tt48.com;
add_header X-cache "$upstream_cache_status from asp";
}
location ~ .*\.(jpg|html)$ {
proxy_cache cache_one;
proxy_cache_valid 200 304 2d;
proxy_cache_valid any 1m;
proxy_cache_key $host$uri;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://www.tt48.com;
add_header X-cache "$upstream_cache_status from jpg";
}
}
复制代码
192.168..56 这个机器上简单的使用搭建了一个web站点,配置文件就不贴出来了, 没东西,192.168.1.48这台机器在缓存1.56web站点上的图片时会出现缓存一半的情况,返回给用户这个图片就打不开了, 不知道问题出在哪里,也许是配置文件有错,也许是nginx的缓存功能不行.... 还请大家帮忙看看,我的配置文件是否有错误
下面是我做压力测试的图,贴出来看看
1.jpg
(44.86 KB, 下载次数: 5)
下载附件
2011-08-18 11:35 上传
2.png
(23.41 KB, 下载次数: 7)
下载附件
2011-08-18 11:35 上传
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2