Fastcgi-cache configuration
It is easy to configure automatic Cache clearing:
1. Check whether the ngx_purge_cache module is installed.
Nginx-V 2> & 1 | grep nginx-cache-purge-o
If nginx-cache-purge is displayed, it indicates that it has been installed.
If there is no output, install:
Sudo add-apt-repository ppa: brianmercer/nginx
Sudo apt-get update
Sudo apt-get install nginx-custom
Use fastcgi_cache to accelerate Nginx sites
When it comes to caching, most of my thoughts are Memcache, Xcache, and Proxy_Cache. FastCgi Cache seems to have been ignored all the time, and FastCgi Cache is also good (I have heard of it recently)
Quote someone's sentence:
Failed to enable fastcgi cache in the lnmp one-key package
Enabling FastCGI Cache is simple
1. Create a folder to store cached files
Defaultmkdir/home/cache/fcgi-p
1 mkdir/home/cache/fcgi-p
2. Modify the nginx. conf file (the LNMP one-key package directory is in/usr/local/nginx/conf/nginx. conf) and add the following to the http layer:
Defaultfastcgi_cache_path/home/cache/fcgi levels = keys_zone = fcgi: 15 m inactive = 1d max_size = 1g;
# If 15 MB is used for memory, 1 GB is used for the maximum disk space.
12 fastcgi_cache_path/home/cache/fcgi levels = keys_zone = fcgi: 15 m inactive = 1d max_size = 1g; #15 m indicates memory usage 1g indicates the maximum disk space
3. Modify the site file in the vhost Directory
Defaultlocation ~ . * \. (Php | php5 )? $
{
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME/home/wwwroot/website directory $ fastcgi_script_name; # Change the website directory to your own
Include fastcgi_params;
Fastcgi_cache fcgi; # indicates enabling the FastCGI cache and specifying a name for it.
Fastcgi_cache_valid 200 302 301 1 h; # cache http status 200 302 301 1 hour
Fastcgi_cache_valid any 1 m; # Other response code is cached for 1 minute.
Fastcgi_cache_min_uses 1; # set the link request to be cached several times.
Fastcgi_cache_use_stale error timeout invalid_header http_500; # define the expiration cache conditions
Fastcgi_cache_key $ request_method: // $ host $ request_uri; # Be sure to add $ request_method as the cache key. Otherwise, if the first request of the HEAD type causes the GET request to return null.
}
12345678910111213 location ~ . * \. (Php | php5 )? $ {Fastcgi_pass 127.0.0.1: 9000; fastcgi_index index. php; fastcgi_param SCRIPT_FILENAME/home/wwwroot/website directory $ fastcgi_script_name; # Change the website directory to your own include fastcgi_params; fastcgi_cache fcgi; # indicates enabling the FastCGI cache and specifying a name for it. Fastcgi_cache_valid 200 302 301 1 h; # cache http status 200 302 301 1 hour fastcgi_cache_valid any 1 m; # Other response code is cached for 1 minute. Fastcgi_cache_min_uses 1; # set the link request to be cached several times. Fastcgi_cache_use_stale error timeout invalid_header http_500; # define the expiration cache fastcgi_cache_key $ request_method: // $ host $ request_uri; # Add $ request_method as the cache key, otherwise, if the first request of the HEAD type causes the GET request to return NULL}
4. Restart nginx.
Default/etc/init. d/nginx restart
1/etc/init. d/nginx restart
5. Open the site and check whether the cache Directory has increased.
Defaultdu-sh/home/cache/fcgi
1 du-sh/home/cache/fcgi
Link: http://jybb.me/nginx-fastcgi_cache
Delete nginx-fastcgi-cache
For example, if a keyword is suddenly found, and the file has been cached before it is modified in the background, it is unknown how long it will take to refresh the file. The solution is to delete the generated file.
But it is not easy to find it. There are two ways:
Find or directly delete all caches one by one
Use two-layer hash to locate files based on the nginx URL-key rules
Because the number of files in the old and high cache is small, the final solution is-keyword filtering.
# Search
Grep-r 'Your keyword '.
# Delete
Grep-rl 'Your keyword'. | xargs rm
You can also
Find | xargs grep 'Your keyword'
Find | xargs grep-l 'Your keyword' | xargs rm
Take notes by the way
# By the way, find limits on searching for files and directories
Find-type f
Find-type d
# Grep -- help-R is also useful!
Grep-r -- include = "*. php"