1. Friends who use virtual hosts recommend using caching plug-ins or php code version caching scheme=> Click here to arrive directly
2. Friends who use independent hosts recommend Nginx's Fastcgi pure static cache scheme=> Click here to arrive directly
1、 Deploy http module
① , single site
fastcgi_cache_path /tmp/wpcache levels=1:2 keys_zone=WORDPRESS:150m inactive=31d max_size=10G; fastcgi_temp_path /tmp/wpcache/temp; fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_cache_use_stale error timeout invalid_header http_500; fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
#Site 1 cache configuration fastcgi_cache_path /tmp/zhangge_cache levels=1:2 keys_zone=zhang.ge:384m inactive=1d max_size=5G; #Site 2 cache configuration #If you want to enable more site caches, please continue to increase them. Note that the cache path and keys_zone of each site should be customized #Ps: The parameters in the code are only examples. In actual use, please modify according to the server configuration fastcgi_cache_path /tmp/zgboke_cache levels=1:2 keys_zone=zgboke.com:384m inactive=1d max_size=5G; #Other configurations can remain unchanged fastcgi_temp_path /tmp/temp_cache; fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_cache_use_stale error timeout invalid_header http_500;
2、 Deploy server module
server( #Other configurations are omitted location ~ [^/]\.php(/|$) { try_files $uri =404; fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; #Fastcgi cache configuration fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; add_header X-Cache "$upstream_cache_status From $host"; fastcgi_cache zhang.ge; fastcgi_cache_valid 200 301 302 1d; } #Other configurations are omitted }
server( #The above configuration is omitted location ~ [^/]\.php(/|$) { try_files $uri =404; fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; #Fastcgi cache configuration fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; add_header X-Cache "$upstream_cache_status From $host"; fastcgi_cache zgboke.com; fastcgi_cache_valid 200 301 302 1d; } #The following configurations are omitted }
3、 Proxy_cache cache
① , http module
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; #There are also several proxy_cache_paths configured for several sites. Note that the cache path and keys_zone need to be customized #Ps: The parameters in the code are only examples. In actual use, please modify according to the server configuration proxy_cache_path /tmp/web1_cache levels=1:2 keys_zone=web1_cache:256m inactive=31d max_size=2g; proxy_cache_path /tmp/web2_cache levels=1:2 keys_zone=web2_cache:256m inactive=31d max_size=2g; proxy_temp_path /tmp/temp_cache;
② , server module
#Other configurations are omitted Proxy_cache web1_cache; # Fill in the keys_zone corresponding to the site proxy_cache_valid 200 302 304 301 1d; proxy_cache_valid any 1m;
#Other configurations are omitted Proxy_cache web2_cache; # Fill in the keys_zone corresponding to the site proxy_cache_valid 200 302 304 301 1d; proxy_cache_valid any 1m;