jackyrar 发表于 2018-11-16 10:06:37

基于nginx实现缓存功能

http {  
    log_formatmain'$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.logmain;
  
    sendfile            on;
  
    tcp_nopush          on;
  
    tcp_nodelay         on;
  
    keepalive_timeout   65;
  
    types_hash_max_size 2048;
  
    include             mime.types;
  
    default_type      application/octet-stream;
  
      #新建缓存
  
      proxy_cache_path /data/cache levels=1:2 keys_zone=nginx:20M max_size=2Ginactive=5;
  
      #为缓存数据添加头部信息
  
      add_header muzigan-Cache "$upstream_cache_status form $server_addr";
  
      upstream static_server {
  
                server 192.168.17.175:80 weight=5;
  
                server 192.168.17.176:80 weight=3;
  
                check interval=3000 rise=2 fall=5 timeout=2000 type=http;
  
                check_http_expect_alive http_2xx http_3xx;
  
      }
  

  
    server {
  
      listen       80 default_server;
  
      server_name_;
  

  

  
      location ~ ^/images {
  
                index index.php index.html;
  
                proxy_pass http://static_server;
  
                #开启缓存
  
                proxy_cache nginx;
  
                #缓存设置
  
                proxy_cache_valid 200 301 302 2m;
  
      }
  
    }
  

  
}


页: [1]
查看完整版本: 基于nginx实现缓存功能