最近在研究缓存的问题,现在我的网站采用的阿里云cdn+Predis(https://note.t4x.org/environment/wordpress-redis-mysql/)的方式。
在使用nginx、tengine的时候发现插件也可以实现类型的功能,稍微研究了一下。SourceByrd's Weblog-https://note.t4x.org/environment/srcache-nginx-module-redis-wordpress/
所需插件:
0 1 2 3 4 |
--add-module=../modules/ngx_devel_kit-0.2.18 --add-module=../modules/set-misc-nginx-module-0.22rc8 --add-module=../modules/srcache-nginx-module-0.22 --add-module=../modules/redis-nginx-module-0.3.7 --add-module=../modules/redis2-nginx-module-0.10 |
nginx编译参数:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
upstream redis { server 1.1.1.120:6379; keepalive 512; } server { listen 80; server_name note.t4x.org; include /usr/local/nginx/conf/wordpress.conf; root /www; index index.php index.html index.htm; default_type text/plain; access_log logs/host.access.log main; srcache_store_private on; srcache_methods GET; srcache_response_cache_control off; set $key $uri; set_escape_uri $escaped_key $key; srcache_default_expire 172800; srcache_fetch GET /redis_get $key; srcache_store PUT /redis_set key=$escaped_key&exptime=$srcache_expire; set $skip_cache 0; #POST请求直接调用后端 if ($request_method = POST) { set $skip_cache 1; } if ($query_string != "") { set $skip_cache 1; } #不要缓存以下部分 if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") { set $skip_cache 1; } #不缓存登陆用户和最近评论的用户 if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; } location = /redis_set { internal; set_unescape_uri $exptime $arg_exptime; set_unescape_uri $key $arg_key; set_md5 $key; redis2_query set $key $echo_request_body; redis2_query expire $key $exptime; redis2_pass redis; } location = /redis_get { internal; set_md5 $redis_key $args; redis_pass redis; } location ~ .*\.php { add_header X-Cached-From $srcache_fetch_status; set_md5 $md5key $key; add_header X-md5-key $md5key; add_header X-Cached-Store $srcache_store_status; add_header X-Key $key; add_header X-Query_String $query_string; add_header X-expire $srcache_expire; add_header X-uri $uri; access_log logs/80-access.log srcache_log; include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_connect_timeout 60; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } |
参考文档:
1:http://www.ttlsa.com/nginx/construction-of-srcache_nginx_redis-caching-system/
2:http://www.tuicool.com/articles/vEv2ey
插件相关:
1:https://github.com/simpl/ngx_devel_kit/
2:https://github.com/openresty/set-misc-nginx-module
3:https://github.com/openresty/srcache-nginx-module
4:https://github.com/openresty/redis2-nginx-moduleSourceByrd's Weblog-https://note.t4x.org/environment/srcache-nginx-module-redis-wordpress/
SourceByrd's Weblog-https://note.t4x.org/environment/srcache-nginx-module-redis-wordpress/