稍微测试了一下nginx基于插件“srcache-nginx-module”做缓存,如果不当之处,请指正。可以参考: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 |
upstream www { server 192.168.2.126:8080; server 192.168.2.127:8080; } server{ listen 80; server_name note.t4x.org; root /var/html/t4x; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; client_max_body_size 50m; client_body_buffer_size 2048k; keepalive_timeout 0; # proxy_intercept_errors on; proxy_pass http://www; proxy_http_version 1.0; proxy_set_header Connection ""; proxy_redirect off; proxy_connect_timeout 300; proxy_read_timeout 600; proxy_send_timeout 300; proxy_buffer_size 512k; proxy_buffers 32 512k; proxy_busy_buffers_size 2048k; proxy_temp_file_write_size 2048k; #proxy_buffering off; proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; add_header X-Cache-Status "$upstream_cache_status"; add_header X-uri "$host$request_uri"; add_header X-Frame-Options SAMEORIGIN; add_header X-Cached-From $srcache_fetch_status; add_header X-Expire $srcache_expire; location ~ .*\.(ico|txt)? { root /var/html/t4x; expires 4h; } location ~ .*\.(css|png|jpg|js|gif)?$ { srcache_store_private on; srcache_methods GET; srcache_response_cache_control off; set $key $uri; set_escape_uri $escaped_key $key; srcache_default_expire 600; srcache_fetch GET /redis_get $key; srcache_store PUT /redis_set key=$escaped_key&exptime=$srcache_expire; add_header X-Cached-From $srcache_fetch_status; set_md5 $md5key $key; add_header X-md5-key $md5key; add_header X-Key $key; add_header X-Query_String $query_string; add_header X-Expire $srcache_expire; } 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 127.0.0.1:6379; } location = /redis_get { internal; set_md5 $redis_key $args; redis_pass 127.0.0.1:6379; } } } |
其他文档:
1:https://github.com/openresty/srcache-nginx-module
2:http://www.ttlsa.com/nginx/construction-of-srcache_nginx_redis-caching-system/
3:https://note.t4x.org/environment/srcache-nginx-module-redis-wordpress/
4:https://note.t4x.org/environment/wordpress-redis-MySQL/
5:https://note.t4x.org/environment/nginx-tomcat-redis-session/ SourceByrd's Weblog-https://note.t4x.org/environment/srcache-nginx-module-redis-jsp/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!