Skip to content

nginx_lua实现的api hmac验证和代理缓存模块

Notifications You must be signed in to change notification settings

linux007/api_proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

概述

nginx +lua实现的一个组件,主要功能包括api token验证, 透明的数据缓存

依赖库

  • redis
  • openresty (nginx + lua)
  • LuaRestyRedisLibrary
  • srcache-nginx-module
  • lua > 5.2

nginx配置

srcache 实现 ```bash server { listen 80; server_name _; root html;

	location = /fetch_cache {
		internal;
		content_by_lua_file /path/to/cache_proxy/fetch.lua;
	} 

	location ~* \.php$ {
		set $cache_key '';
		lua_code_cache off;
		#设置参数
		set $fetch_skip 1;
		set $store_skip 1;
		access_by_lua_file /path/to/access.lua;

		#rewrite  处理缓存,生成缓存键
		rewrite_by_lua_file /path/to/cache_proxy/rewrite.lua;

		srcache_fetch_skip $fetch_skip;
		srcache_store_skip $store_skip;

		srcache_fetch GET /fetch_cache key=$cache_key;
		srcache_store PUT /fetch_cache key=$cache_key;

		add_header X-SRCache-Fetch-Status $srcache_fetch_status;
		add_header X-SRCache-Store-Status $srcache_store_status;

		try_files $uri =404;
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		include fastcgi.conf; 

	}

}

缓存失效风暴

为了防止缓存失效引起的雪崩现象,增加一个加锁版本的cache,具体cache.lua。

About

nginx_lua实现的api hmac验证和代理缓存模块

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published