TOUVE 发表于 2018-11-10 08:50:26

使用nginx cache缓存网站数据实践

root@nginx>> cat nginx.conf  
user            nginx;
  
worker_processes1;
  
error_log /var/log/nginx/error.log;
  
pid       /var/run/nginx.pid;
  
events {
  
   worker_connections1024;
  
}
  
http {
  
   include      /etc/nginx/mime.types;
  
   default_type application/octet-stream;
  
   log_formatmain'$remote_addr - $remote_user [$time_local]"$request" '
  
                      '$status $body_bytes_sent"$http_referer" '
  
                     '"$http_user_agent" "$http_x_forwarded_for"'
  
                                       '"addr:$upstream_addr-status:$upstream_status-cachestatus:$upstream_cache_status"';
  
   sendfile      on;
  
   keepalive_timeout65;
  
       proxy_cache_path /tmp/ngx_cache levels=1:2 keys_zone=cache_one:100m inactive=1dmax_size=5g;
  
       upstream server_pool {
  
                server 127.0.0.1:8080;
  
       }
  
   server {
  
                listen 80;
  
       location / {
  
                        proxy_passhttp://server_pool;
  
                        proxy_next_upstreamhttp_502 http_504 error timeout invalid_header;
  
                        proxy_cache cache_one;
  
                        proxy_cache_valid 200304 12h;
  
                        proxy_cache_valid 301302 1m;
  
                        proxy_cache_valid any 1m;
  
                        proxy_cache_key$host$uri$is_args$args;
  
                        proxy_set_header Host$host;
  
                        proxy_set_headerX-Forwarded-For $remote_addr;
  
                        expires 1d;
  
       }
  
       access_log /var/log/nginx/cache_access.log main;
  
   }
  
       server {
  
                listen 8080;
  
                location / {
  
                        root/usr/share/nginx/html;
  
                        index index.htmlindex.htm;
  
                }
  
       }
  
}


页: [1]
查看完整版本: 使用nginx cache缓存网站数据实践