依赖:lua-resty-http
基于Nginx&Lua 和Netflix Eureka的微服务网关。
重新架构了内部组件,采用插件模式。
基于Nginx和Lua module。需要 安装Nginx Lua环境 或者直接下载 openresty 编译安装。
git clone http://github.com/tietang/ngx-lua-zuul –depth=1
如果没有Eureka环境,也可以编译安装本例子中的EurekaDemo服务,参考 编译和运行eureka-demo服务 中的相关内容。
下载代码后:
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 文件 include "/path/to/lua/ngx_conf/ngx_inlude_http.conf";
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服务 中的相关内容。