Nginx supports HTML pseudo static pages with Ngx_cache_purge module cache acceleration

Source: Internet
Author: User
Tags comments html page wordpress cache wordpress cache plugin nginx reverse proxy

Nginx cache acceleration steps are as follows


One, add module





The Nginx cache shared by this article requires additional compilation of ngx_cache_purge modules. As for the download module, recompile will be said later.





Second, nginx configuration





To use this caching feature, it is recommended to recreate a server module (before replacing), which is the rule that the Zhanggo blog is currently using (deleted my custom pseudo static rules to avoid confusing):





####################################################################################################


# Nginx opens Fastcgi_cache-purge cache acceleration, supports HTML pseudo static page by Zhanggo Blog


# Article Address: http://zhangge.net/5042.html


# Reference ①:http://jybb.me/nginx-wordpress-fastcgi_cache-purge


# Reference ②:https://rtcamp.com/wordpress-nginx/tutorials/single-site/fastcgi-cache-with-purging/


# reproduced this article please be sure to retain the above statement, thank you for your cooperation!


####################################################################################################





#下面各个参数的含义请自行百度, I won't go into it.


#下面2行的中的wpcache路径请自行提前创建, otherwise the path may not exist and cannot be started nginx,max_size please set it according to the partition size


Fastcgi_cache_path/tmp/cache/wpcache levels=1:2 keys_zone=wordpress:250m inactive=1d Max_size=1G;


Fastcgi_temp_path/tmp/cache/wpcache/temp;


Fastcgi_cache_key "$scheme $request_method$host$request_uri";


Fastcgi_cache_use_stale error timeout Invalid_header http_500;


#忽略一切nocache申明, avoid not caching pseudo static, etc.


Fastcgi_ignore_headers Cache-control Expires Set-cookie;





Server


{


Listen 80;


#请修改为自己的域名


server_name zhangge.net;


Index index.html index.htm index.php default.html default.htm default.php;


#请修改为自己网站的存放路径


Root/home/wwwroot/zhangge.net;





Set $skip _cache 0;


#post访问不缓存


if ($request _method = POST) {


Set $skip _cache 1;


}


#动态查询不缓存


if ($query _string!= "") {


Set $skip _cache 1;


}


#后台等特定页面不缓存 (Other requirements please add yourself)


if ($request _uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap" (_index)? XML ") {


Set $skip _cache 1;


}


#对登录用户, commented on users do not show caching (this rule Zhanggo blog is not used, all see is cache)


if ($http _cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {


Set $skip _cache 1;


}


#这里请参考你网站之前的配置, especially the sock path, the mistake is 502!


Location ~ [^/]\.php (/|$)


{


Try_files $uri = 404;


Fastcgi_pass Unix:/tmp/php-cgi.sock;


Fastcgi_index index.php;


Include fastcgi.conf;


#新增的缓存规则


Fastcgi_cache_bypass $skip _cache;


Fastcgi_no_cache $skip _cache;


Add_header X-cache "$upstream _cache_status from $host";


Fastcgi_cache WORDPRESS;


Fastcgi_cache_valid 302 1d;


}


Location/{


#此处可以添加自定义的伪静态规则 (your new pseudo static rules can be added to this, no more)


Try_files $uri $uri//index.php $args;


rewrite/wp-admin$ $scheme://$host $uri/permanent;


}


#缓存清理配置 (optional module, please look at the description below)


Location ~/purge (/.*) {


Allow 127.0.0.1;


Allow "here to fill out your server's real extranet IP";


Deny all;


Fastcgi_cache_purge WORDPRESS "$scheme $request_method$host$1";


}





Location ~* ^.+\. (ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar| MID|MIDI|WAV|BMP|RTF) $ {


Access_log off; Log_not_found off; Expires Max;


}





Location =/robots.txt {access_log off; log_not_found off;}


Location ~/\. {Deny all; Access_log off; log_not_found off;}


#请注意修改日志路径


Access_log/home/wwwlogs/zhangge.net.log access;


}





Please carefully read all the comments in the code, the modification of the changes, the creation of the creation, the supplement according to the actual situation supplemented, otherwise after use to find Zhanggo spit a variety of problems!





third, the installation of Plug-ins





As mentioned above, Fastcgi_cache has a customized wordpress cache cleanup Plugin: Nginx Helper





So, next we're going to install this plugin. Very simple, directly into the WordPress background plug-in installation interface search Nginx Helper keyword online installation can be.





After installation, the plugin settings interface is opened from the background tool ==> "Nginx Helper" as follows:


Ps: Incidentally, the meaning of the following 2 items:

Record plug-in log: Check this option, the plugin settings below will show the log record storage path. This function is mainly used to test the settings of plug-ins, such as to the cached text to make a new comment, and then see if there is a delete record in the log.

Insert Cache information: Check this option, the front page source code at the bottom of the page will insert the cached information, similar to the following:

<!--Cached using Nginx-helper on 2015-05-30 12:34:22. It took 162 queries executed in 1.922 seconds.-->
<!--Visit Http://wordpress.org/extend/plugins/nginx-helper/faq/for more details-->

When you enable cache cleanup on the hook, the following options appear:


How to set up, should look at the map to understand it? Otherwise Zhanggo bitter force in Chinese to mark a long time to waste Kung Fu!

Cleanup Mode selection





I also marked the above figure more clearly, or explain it in detail!





①, purge mode





This pattern requires retention of the purge cleanup path in the Nginx configuration above, and a request is generated when scavenging.





For security reasons, General purge will not be completely open! Only a specific IP can be accessed, so if you use a CDN friend, and then use the mode one, you need to force a real IP in the hosts on the server, do not understand the words to give up this mode bar.





②, File mode





Mode two is to clean the corresponding cache file directly, do not need to request purge this cleanup path, so use mode two, do not need to configure the above Nginx purge rules (I personally recommend this mode).





Because the cache path defined by the plugin author is/var/run/nginx-cache, and we may be able to customize the cache path according to the actual server, this will cause the plugin to be unable to find the cached file and delete the cache path.





Solution:





Quite simply, add the following code to the wp-config.php in the WordPress root directory:


Define the storage path of the cache according to the actual situation


Define (' Rt_wp_nginx_helper_cache_path ', '/tmp/cache/wpcache ');





Define the storage path of the cache according to the actual situation


Define (' Rt_wp_nginx_helper_cache_path ', '/tmp/cache/wpcache ');





Ps: Do not know how to add to the line, you can add to the define (' Wplang ', ' zh_cn '); Can be followed by. After adding, it is recommended to overload PHP to ensure that the variable takes effect (primarily for web sites that have PHP cached).





third, Effect preview





①, caching effects





Replace the new configuration, and after overloading Nginx, access the foreground page, see header, there will be a X-cache flag.





X-cache generally have 3 states: MISS, HIT, BYPASS.





Miss indicates an unspecified hit





That is, the page has not been cached, newly published or just deleted pages, the first access will appear this state (figure).





Hit represents a cache hit





Open a cached page, such as the article content HTML page, F5 refresh several times to see the image cache hit status in the header header information in the F12 developer mode:


Bypass represents a cache blacklist

That is, the page path is set to not be cached in the Nginx rule (set $skip _cache 1;), such as WP background, view header:


If you find that the page you want to cache is this state, you can check to see if the exclusion rule contains this path! Conversely, if you find that the background login is not, or a variety of landing state loss problems, you should go to the exclusion rule plus the page path keyword.


②, Cleaning effect

This plugin and cache collocation is very useful, whether we are publishing articles, or someone to comment, Plug-ins can be based on our settings to clean up the corresponding cache! For example, someone published an automatic audit through the comments (or Bo Master audit through a comment), Plug-ins will automatically delete comments related to the article cache, the specific look at the figure Zhanggo posted on the callout can.

How do I see if my plug-in is working correctly? Very simple, check to open the plugin log, and then click Update an old article, finally open the plugin log to see whether to delete records.

With a friend of Linux, you can view the log directly using the TAILF command, and then update the article to see the effect, as shown in the following figure:


To verify that the cache is really deleted, we can first open the browser's developer mode, navigate to the network interface, and then visit the article just updated to see the following status:


Obviously, the cache has been successfully deleted, the home page does not look, it is certainly the state.



Open Nginx cache acceleration for Web sites, supporting HTML pseudo static pages

This article is about how to solve the CPU overhead associated with this real-time generation of thumbnails.

The idea is very simple, since you want to build in real time, then I will be your generated thumbnail cache a good! During my testing, I found that the Nginx cache can also cache pseudo static HTML pages, and can replace Wp-super-cache cache plug-ins. Believe that most of the CDN is also used in this principle, such as Baidu cloud acceleration, we can find a "Server:yunjiasu-nginx" in the header logo.

First, the agent mode

Proxy mode, where the specified content is cached when using Nginx reverse proxy, and the module used is Proxy_cache. Many of the tutorials on the web say that this pattern must be used in a reverse proxy, as if it could not be used in a single server. In fact, we use a little trick, will Nginx this machine's 80-port agent forward to the local 8080-port can be disguised to open the reverse proxy mode, in this period, you can specify the cache content, and continue to look down!




①, download module





The module used is ngx_cache_purge, official address: http://labs.frickle.com/files/, we can pick a new version to download to the server, such as http://labs.frickle.com/files/ Ngx_cache_purge-2.3.tar.gz


Cd/usr/local/src


#下载


wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz


#解压


Tar zxvf ngx_cache_purge-2.3.tar.gz





Cd/usr/local/src


#下载


wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz


#解压


Tar zxvf ngx_cache_purge-2.3.tar.gz





②, recompiling





So the-v command is executed first to see if Nginx has compiled the module,


[Marsge@mars_server ~]$ Nginx-v


Tengine version:tengine/2.1.0 (nginx/1.6.2)


Built by GCC 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)


TLS SNI Support Enabled


Configure arguments:--user=www--group=www--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ Gzip_static_module--with-http_concat_module--add-module=. /ngx_cache_purge-2.3--with-http_image_filter_module--add-module=. /ngx_slowfs_cache-1.9


[Alert] could not open error log file:open () "/usr/local/nginx/logs/error.log" failed (13:permission denied)


2015/05/20 21:38:38 [warn] 30552#0:the ' user ' directive makes sense only if the master process runs with super-user Privi Leges, ignored In/usr/local/nginx/conf/nginx.conf:1


Loaded modules:


Ngx_core_module (Static)


Ngx_errlog_module (Static)


...





[Marsge@mars_server ~]$ Nginx-v


Tengine version:tengine/2.1.0 (nginx/1.6.2)


Built by GCC 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)


TLS SNI Support Enabled


Configure arguments:--user=www--group=www--prefix=/usr/local/nginx--with-http_stub_status_module--with-http_ Gzip_static_module--with-http_concat_module--add-module=. /ngx_cache_purge-2.3--with-http_image_filter_module--add-module=. /ngx_slowfs_cache-1.9


[Alert] could not open error log file:open () "/usr/local/nginx/logs/error.log" failed (13:permission denied)


2015/05/20 21:38:38 [warn] 30552#0:the ' user ' directive makes sense only if the master process runs with super-user Privi Leges, ignored In/usr/local/nginx/conf/nginx.conf:1


Loaded modules:


Ngx_core_module (Static)


Ngx_errlog_module (Static)


...





If Ngx_cache_purge is not found in the compilation parameters, you will need to recompile the Nginx and add new compilation parameters:


#注意第一步解压的文件夹和nginx源码在同一个目录


--add-module=.. /ngx_cache_purge-2.3





#注意第一步解压的文件夹和nginx源码在同一个目录


--add-module=.. /ngx_cache_purge-2.3





I now use Taobao open Tengine, you can use the dynamic loading module function.





③, new configuration





A. New cache configuration in HTTP context:


HTTP {


#以上略


# #cache # #


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/tmp/nginx_temp_cache1; #临时缓存目录


Proxy_cache_path/home/wwwroot/cache1 levels=1:2 keys_zone=cache_one:200m inactive=30d max_size=5g; #设置缓存存放, do not understand the parameters of their own Baidu search under


# #end # #


#以下略


....


}





HTTP {


#以上略


# #cache # #


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/tmp/nginx_temp_cache1; #临时缓存目录


Proxy_cache_path/home/wwwroot/cache1 levels=1:2 keys_zone=cache_one:200m inactive=30d max_size=5g; #设置缓存存放, do not understand the parameters of their own Baidu search under


# #end # #


#以下略


....


}





Ps: The directory that appears in the above configuration, please manually create it using mkdir after saving the configuration.





B. Modify the original server module of the website as follows:


Server


{


#将之前监听修改成监听本地8080, other configurations remain unchanged


Listen 127.0.0.1:8080;


server_name zhangge.net;


#以下内容略 ...


}





Server


{


#将之前监听修改成监听本地8080, other configurations remain unchanged


Listen 127.0.0.1:8080;


server_name zhangge.net;


#以下内容略 ...


}





B. The following add a reverse proxy server module for forwarding requests to local 8080, in disguise to implement reverse proxy mode:


server {


Listen 80;


server_name zhangge.net;


#缓存清理模块


Location ~/purge (/.*) {


Allow 127.0.0.1;


Allow 192.168.1.101; #此处表示允许访问缓存清理页面的IP


Deny all;


Proxy_cache_purge Cache_one $host $1$is_args$args;


}


#缓存html页面, can cache pseudo static "This is the bright spot!" 】


Location ~. *\.html$ {


Proxy_pass http://127.0.0.1:8080;


Proxy_redirect off;


Proxy_set_header Host $host;


Proxy_cache Cache_one;


#状态为200, 302 cache 1 days


Proxy_cache_valid 302 1d;


#状态为301的缓存2天


Proxy_cache_valid 2d;


Proxy_cache_valid any 1m;


#浏览器过期时间设置4小时


Expires 4h;


#忽略头部禁止缓存申明, similar to the mandatory caching function with CDN


Proxy_ignore_headers "Cache-control" "Expires" "Set-cookie";


#在header中插入缓存状态, the hit cache is hit, and the Miss is dead.


Add_header Nginx-cache "$upstream _cache_status";


}


#图片缓存设置, if not using the Nginx thumbnail function, this can not be, the effect is not obvious


Location ~. *\. (Gif|jpg|png|css|jsico) (.*) {


Proxy_pass http://127.0.0.1:8080;


Proxy_redirect off;


Proxy_set_header Host $host;


Proxy_cache Cache_one;


Proxy_cache_valid 302 30d;


Proxy_cache_valid 1d;


Proxy_cache_valid any 1m;


Expires 30d;


Proxy_ignore_headers "Cache-control" "Expires" "Set-cookie";


Add_header Nginx-cache "$upstream _cache_status";


}


#动态页面直接放过不缓存


Location ~. *\. (PHP) (.*) {


Proxy_pass http://127.0.0.1:8080;


Proxy_set_header Host $host;


Proxy_set_header X-real-ip $remote _addr;


Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;


}


#设置缓存黑名单, do not cache the specified page, such as WP background or other pages that need to log on, separated by delimiters


Location ~ ^/(Wp-admin|system) (. *) $ {


Proxy_pass http://127.0.0.1:8080;


Proxy_set_header Host $host;


Proxy_set_header X-real-ip $remote _addr;


Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;


}


#缓存以斜杠结尾的页面, similar to CDN's directory cache, if there are problems please cancel caching mechanism


Location ~ ^ (. *)/$ {


Proxy_pass http://127.0.0.1:8080;


Proxy_redirect off;


Proxy_set_header Host $host;


Proxy_cache Cache_one;


Proxy_cache_valid 302 1d;


Proxy_cache_valid 1d;


Proxy_cache_valid any 1m;


Expires 1h;


Proxy_ignore_headers "Cache-control" "Expires" "Set-cookie";


Add_header Nginx-cache "$upstream _cache_status";


}


Location/{


Proxy_pass http://127.0.0.1:8080;


Proxy_set_header Host $host;


Proxy_set_header X-real-ip $remote _addr;


Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;


}


}





server {


Listen 80;


server_name zhangge.net;


#缓存清理模块


Location ~/purge (/.*) {


Allow 127.0.0.1;


Allow 192.168.1.101; #此处表示允许访问缓存清理页面的IP


Deny all;


Proxy_cache_purge Cache_one $host $1$is_args$args;


}


#缓存html页面, can cache pseudo static "This is the bright spot!" 】


Location ~. *\.html$ {


Proxy_pass http://127.0.0.1:8080;


Proxy_redirect off;


Proxy_set_header Host $host;


Proxy_cache Cache_one;


#状态为200, 302 cache 1 days


Proxy_cache_valid 302 1d;


#状态为301的缓存2天


Proxy_cache_valid 2d;


Proxy_cache_valid any 1m;


#浏览器过期时间设置4小时


Expires 4h;


#忽略头部禁止缓存申明, similar to the mandatory caching function with CDN


Proxy_ignore_headers "Cache-control" "Expires" "Set-cookie";


#在header中插入缓存状态, the hit cache is hit, and the Miss is dead.


Add_header Nginx-cache "$upstream _cache_status";


}


#图片缓存设置, if not using the Nginx thumbnail function, this can not be, the effect is not obvious


Location ~. *\. (Gif|jpg|png|css|jsico) (.*) {


Proxy_pass http://127.0.0.1:8080;


Proxy_redirect off;


Proxy_set_header Host $host;


Proxy_cache Cache_one;


Proxy_cache_valid 302 30d;


Proxy_cache_valid 1d;


Proxy_cache_valid any 1m;


Expires 30d;


Proxy_ignore_headers "Cache-control" "Expires" "Set-cookie";


Add_header Nginx-cache "$upstream _cache_status";


}


#动态页面直接放过不缓存


Location ~. *\. (PHP) (.*) {


Proxy_pass http://127.0.0.1:8080;


Proxy_set_header Host $host;


Proxy_set_header X-real-ip $remote _addr;


Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;


}


#设置缓存黑名单, do not cache the specified page, such as WP background or other pages that need to log on, separated by delimiters


Location ~ ^/(Wp-admin|system) (. *) $ {


Proxy_pass http://127.0.0.1:8080;


Proxy_set_header Host $host;


Proxy_set_header X-real-ip $remote _addr;


Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;


}


#缓存以斜杠结尾的页面, similar to CDN's directory cache, if there are problems please cancel caching mechanism


Location ~ ^ (. *)/$ {


Proxy_pass http://127.0.0.1:8080;


Proxy_redirect off;


Proxy_set_header Host $host;


Proxy_cache Cache_one;


Proxy_cache_valid 302 1d;


Proxy_cache_valid 1d;


Proxy_cache_valid any 1m;


Expires 1h;


Proxy_ignore_headers "Cache-control" "Expires" "Set-cookie";


Add_header Nginx-cache "$upstream _cache_status";


}


Location/{


Proxy_pass http://127.0.0.1:8080;


Proxy_set_header Host $host;


Proxy_set_header X-real-ip $remote _addr;


Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;


}


}





After all is saved, execute nginx-s reload let the configuration take effect. Now you go to visit the site's HTML page, refresh once you can see the effect! Loading speed must be a qualitative leap! And you can see the identity of Nginx-cache HIT in the network state of F12 development mode!





④, scavenging cache





Cleaning up the cache is a bit of trouble, I have made many times also still feel not good! There have also been a number of pioneers on the Web sharing automated cleanup scripts or batch cleanup code. But the use of the next is not good good.





Let's talk about cleaning up the way! In the configuration of part A, we have joined the purge Cache cleanup page, assuming that a URL is http://192.168.1.1/test.html by accessing the http://192.168.1.1/purge/test.html You can clear the cache for this URL (my actual test is often 404 ...). )。




second, the local model





In the first proxy mode, we use the local forwarding to implement the Nginx caching function under the reverse proxy, and can cache the HTML pseudo static page. From the overall configuration can be seen, has been very close to Baidu cloud acceleration, such as the caching function of CDN! There is no small help to understand the CDN cache!





Now share, how do you implement Nginx caching without the reverse proxy mode? Very simple, further with the help of Ngx_slowfs_cache module can, this is Zhanggo blog in the mode, how to achieve, and continue to look down.





①, download module





This mode requires downloading 2 cache modules: Ngx_cache_purge and Ngx_slowfs_cache. All 2 modules are from a website, the download address is still http://labs.frickle.com/files/, pick a latest version of the download can be, such as:





Http://labs.frickle.com/files/ngx_slowfs_cache-1.9.tar.gz





②, recompiling





As with the first pattern, add 2--add-module to recompile nginx:


--add-module=.. /ngx_cache_purge-2.3--add-module=. /ngx_slowfs_cache-1.9





--add-module=.. /ngx_cache_purge-2.3--add-module=. /ngx_slowfs_cache-1.9





Specifically do not repeat, refer to the above and the blog before the sharing can be done.


③, new configuration





I. Add the following configuration to the HTTP context:


HTTP {


#以上略


Slowfs_cache_path/home/wwwroot/cache levels=1:2 keys_zone=fastcache:256m inactive=1d max_size=5g;


Slowfs_temp_path/tmp/nginx_temp_cache 1 2;


#以下略


}





HTTP {


#以上略


Slowfs_cache_path/home/wwwroot/cache levels=1:2 keys_zone=fastcache:256m inactive=1d max_size=5g;


Slowfs_temp_path/tmp/nginx_temp_cache 1 2;


#以下略


}





Ps: The directories involved in the above configuration are created manually.





Ii. Add the following configuration in the server module:


#新增缓存清理配置


Location ~/purge (/.*) {


Allow 127.0.0.1;


Allow 192.168.1.101;


Deny all;


Slowfs_cache_purge Fastcache $;


}


#在上一篇文章的缩略图模块后新增缓存 to cache the generated thumbnails to disk (see article for details)


Location ~. *\. (gif|jpg|jpeg|png|bmp) $ {


Set $width ';


Set $height ';


Set $width $arg _width;


Set $height $arg _height;


if ($width!= ') {


Add_header Thumbnail "by Nginx";


}


if ($height = ') {


Set $height '-';


}


if ($width = ') {


Set $width '-';


Set $height '-';


}


Image_filter resize $width $height;


Image_filter_buffer 5M;


Image_filter_jpeg_quality 80;


Image_filter_transparency on;





#新增缓存配置


Slowfs_cache Fastcache;


Slowfs_cache_key $uri;


Slowfs_cache_valid 1d;


#在header中插入缓存标识, for example: Hit/miss from Zhangge.net


Add_header X-cache ' $slowfs _cache_status from $host ';


Expires Max;


}





#新增缓存清理配置


Location ~/purge (/.*) {


Allow 127.0.0.1;


Allow 192.168.1.101;


Deny all;


Slowfs_cache_purge Fastcache $;


}


#在上一篇文章的缩略图模块后新增缓存 to cache the generated thumbnails to disk (see article for details)


Location ~. *\. (gif|jpg|jpeg|png|bmp) $ {


Set $width ';


Set $height ';


Set $width $arg _width;


Set $height $arg _height;


if ($width!= ') {


Add_header Thumbnail "by Nginx";


}


if ($height = ') {


Set $height '-';


}


if ($width = ') {


Set $width '-';


Set $height '-';


}


Image_filter resize $width $height;


Image_filter_buffer 5M;


Image_filter_jpeg_quality 80;


Image_filter_transparency on;





#新增缓存配置


Slowfs_cache Fastcache;


Slowfs_cache_key $uri;


Slowfs_cache_valid 1d;


#在header中插入缓存标识, for example: Hit/miss from Zhangge.net


Add_header X-cache ' $slowfs _cache_status from $host ';


Expires Max;


}





After saving, perform nginx-s reload overload Nginx. Test found that this model does not seem to cache the HTML pseudo static page, a little regret, interested in the children's shoes can be in-depth study to see, may be I did not test in place.


Iii. Summary of Practice

Well, through the above toss, we have solved the Nginx real-time generation of thumbnails caused by the CPU cost problem! And, from the proxy-mode cache, we can even cache HTML pseudo static pages, what does that mean? Obsessive-Compulsive disorder can be ruthless discard a wordpress cache plugin! However, Zhanggo blog temporarily or use their own write PHP code to achieve static caching, nothing else, mainly for the convenience of management.

Overall, for nginx thumbnails and caching, I am still very satisfied, like tossing friends can also try, perhaps you can find more experience than this article!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.