nginx 多盤做緩存

worker_processes  8;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  65535;
}


http {
    include       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" "$upstream_cache_status" "$host" "$request_time"';

    access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    resolver  8.8.8.8;

    #gzip  on;
client_body_buffer_size  512k;
 proxy_connect_timeout    5;
 proxy_read_timeout       60;
 proxy_send_timeout       5;
 proxy_buffer_size        16k;
 proxy_buffers            4 64k;
 proxy_busy_buffers_size 128k;
 proxy_temp_file_write_size 128k;
proxy_temp_path   /data/tmp;

proxy_cache_path  /data/cache1  levels=1:2   keys_zone=cache_1:200m inactive=365d max_size=112g use_temp_path=off;
proxy_cache_path  /data/cache2  levels=1:2   keys_zone=cache_2:200m inactive=365d max_size=120g use_temp_path=off;
proxy_cache_path  /data/cache3  levels=1:2   keys_zone=cache_3:200m inactive=365d max_size=120g use_temp_path=off;
proxy_cache_path  /data/cache4  levels=1:2   keys_zone=cache_4:200m inactive=365d max_size=120g use_temp_path=off;
proxy_cache_path  /data/cache5  levels=1:2   keys_zone=cache_5:200m inactive=365d max_size=120g use_temp_path=off;

split_clients $request_uri $disk {
        20% 1;
        20% 2;
        20% 3;
        20% 4;
        20% 5;
}

#server {
#        listen     80 default_server;
#        server_name _;

#       location / {
#               return 403;
#       }
#}

server {
        listen       80;
       # server_name  hpcc-page.cnc.ccgslb.com.cn img3.2345.com;
        location / {                                                                                                                                 
        proxy_set_header Accept-Encoding "";                                                                                                         
        proxy_pass http://$host;                                                                                                                     
        proxy_cache_key $request_uri;                                                                                                                
        proxy_cache cache_$disk;                                                                                                                     
        proxy_cache_valid 200 302 1d;                                                                                                                
        proxy_cache_valid 404      1d;                                                                                                               
        #aio threads=pool_$disk;                                                                                                                     
        add_header  Nginx-Cache "$upstream_cache_status";                                                                                            
                        sendfile on;                                                                                                                                 
        }

        location /nginx_status {
          stub_status on;
          access_log   off;
          allow 127.0.0.1;
          deny all;
        }

}

}

公司需要做緩存,squid 因爲好久沒用,還的重新學,就選nginx了;之前都是單塊盤做,這次用多塊盤做緩存,發現很好用,而且比squid簡單。

下面是硬盤圖和tsar監控的一些數據


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章