nginx:cache

http{
    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 /home/temp_dir; 
    proxy_cache_path /home/cache levels=1:2 keys_zone=cache_one:50m inactive=20m max 30g;
}

location /gou/detail-id-116 { 
    ##cache 
    index index.html index.htm index.php; 
    #cache
    proxy_cache_min_uses 3;
    #use the cache named cache_one as configured above proxy_cache_path keys_zone=cache_one
    proxy_cache cache_one; 
    #Cache validity proxy_cache_valid any 1d; any validity period of 1 day
    proxy_cache_valid 200 302 1h;         
    proxy_cache_key $host$uri$is_args$args; 
    proxy_pass http://...;  #Does
    not process the specified response header returned by the back-end server, the function is to be able to Cache dynamic pages, such as .php pages, if you do not add this line, you can only cache static page content
    proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie";
    #-1 means not to cache
    expires 30d; 
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #If 
    any parameter value is not empty, or not equal to 0, nginx will not look for the cache, and proxy forwarding directly
    #proxy_cache_bypass $ cookie_nocache $arg_nocache$arg_comment;
    #proxy_cache_methods GET HEAD POST;

===================================================== ======
proxy_cache_path has two required parameters, the first parameter is the cache directory, and the second parameter keys_zone specifies the cache name and the size of the memory space occupied (Note: 10m in the example is the cache content element in the memory. The size of the data information is limited, if you want to limit the total size of the cache, you need to use the max_size parameter)

such as:
// Cache directory: /data/nginx/cache
// Cache name: one
// Cache memory space: 10m
// Loader Each iteration process executes up to 300 milliseconds
// The loader loads up to 200 files per iteration process
// The cache hard disk space is up to 200m
proxy_cache_path /data/nginx/cache keys_zone=one:10m loader_threshold=300
loader_files=200 max_size= 200m;

================================================= ========
1) nginx first hashes the request address /1.png with md5 to get e0bd86606797639426a92306b1b98ad9
The parameters of md5 are in the above configuration:
proxy_cache_key 
value, such as md5("www.xxx.com/gou /detail-id-116");

2) level=1:2 is to take the last digit 9 out to create a directory, then create a directory for the two digits in front of 9, and finally put the cache file just obtained in the 9/ad directory.
The same way of reasoning, if level=1:1, then the path of the cache file is /usr/local/nginx/cache/9/d/e0bd86606797639426a92306b1b98ad9
=================== =======================================
memcached
memcached connect_timeout: Established between NGINX and memcached server Connection timeout.
memcached_send_timeout: The timeout for writing requests to the memcached server. memcached_read_timeout: Timeout for reading responses from the memcached server.
===================================================== ======
http{
   memcached_send_timeout 30s;
   memcached_connect_timeout 30s;
   memcached_read_timeout 30s;
   server{
      location /python/ {
         set memcachedkey"memcachedkey"request_method$request_uri";
         charset utf-8;
         memcached_pass 127.0.0.1:11211;
         #error_page 404 502 504 = @pythonfallback;
         default_type text/html;
      }
      location @pythonfallback {
         rewrite ^/python/(.*) /$1 break;
         proxy_pass http://127.0.0.1:5000;
         proxy_set_header X-Cache-Key "requestmethodrequestmethodrequest_uri";
      }
   }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326252182&siteId=291194637