依賴:lua-resty-http
基于Nginx&Lua 和Netflix Eureka的微服務網關。
重新架構了內部組件,采用插件模式。
- 服務發現
- Eureka Discovery
- 抽象discovery,用來支持多種服務發現?規劃中...
- 動態路由
- 負載均衡
- 加權輪詢
- 基于響應時間的動態權重輪詢?開發中...
- 簡單監控
- 隔離降級
- 限流
- metrics
- 認證安全?規劃中。。。
- 監控頁面?開發中...
架構圖:

使用方法
基于Nginx和Lua module。需要安裝Nginx Lua環境或者直接下載openresty編譯安裝。
安裝和配置ngx-lua-zuul
下載代碼到/path/to/nginx/lua/lib/
git clone http://github.com/tietang/ngx-lua-zuul --depth=1
例子Eureka 服務
如果沒有Eureka環境,也可以編譯安裝本例子中的EurekaDemo服務,參考編譯和運行eureka-demo服務中的相關內容。
部署dicovery例子服務:
下載代碼后:
cd /path/to/ngx_lua-zuul/demo/java
mvn clean install
將下載的代碼中的lua文件夾放到部署目錄/path/to/nginx
,修改/path/to/nginx/lua/ngx_conf/lua.ngx_conf
文件中的lua_package_path
為你的真實路徑:
lua_package_path "/path/to/nginx/lua/lib/?.lua;;";
修改/path/to/nginx/conf/nginx.conf
文件
http 節點中添加
include "/path/to/lua/ngx_conf/ngx_inlude_http.conf";
server節點中添加
include "/path/to/nginx/lua/ngx_conf/ngx_inlude_server.conf";
參考配置
#user nobody;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include "/Users/tietang/nginx/nginx/lua/ngx_conf/ngx_inlude_http.conf";
server {
include "/Users/tietang/nginx/nginx/lua/ngx_conf/ngx_inlude_server.conf";
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
location = / {
set $dir $document_root;
root $dir/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
運行測試
啟動所有的demo服務:discovery,api,zuul;
啟動nginx;
打開瀏覽器:http://127.0.0.1:8000/api/test/0/0
其測試api參考編譯和運行eureka-demo服務中的相關內容。