Nginx缓存命中长$ request_time

时间:2014-07-23 12:11:41

标签: nginx

$upstream_cache_status是HIT,但$request_time有时持续5秒,问题是什么?

我的nginx.conf

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

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;

    client_max_body_size 30M;

    proxy_temp_path /tmp/proxy_temp_dir;
    proxy_cache_path /tmp/proxy_cache_dir levels=1:2 keys_zone=cache:500m inactive=1d max_size=500m;

    log_format cache_log '$remote_addr - [$request_time] $status $upstream_cache_status "$request"';

    server {
        access_log  logs/access.log cache_log;
        error_log   logs/error.log error;

        proxy_cache cache;
        proxy_cache_valid 10m;

        location / {
            proxy_next_upstream http_502 error timeout;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_pass http://xxxxxx;
        }
    }

    include /usr/local/openresty/nginx/conf/vhosts/*.conf;
}

和access.log:

x.x.x.x - [5.076] 200 HIT "GET /xxx"
x.x.x.x - [0.092] 200 HIT "GET /xxx"

相同的请求网址,两者都被点击缓存,为什么$request_time会持续5秒或更长时间?

感谢。

1 个答案:

答案 0 :(得分:0)

这是一个磁盘IO问题,我将proxy_cache_path移动到另一个SSD,问题解决了。