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 \.";
#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的緩存功能不行.... 還請大家幫忙看看,我的配置文件是否有錯誤
下面是我做壓力測試的圖,貼出來看看
[火星人
]
nginx的緩存問題已經有682次圍觀
http://coctec.com/docs/service/show-post-2052.html