skipper 具有强大的http 路由功能,fabio 是一个方便的基于consul 的负载均衡软件,
我们可以方便的使用skipper 路由功能进行fabio的扩展,使用registrator 进行服务注册

环境准备

  • docker-compose
version: "3"
services:
fabio:
image: fabiolb/fabio
ports:
- "9999:9999"
- "9998:9998"
volumes:
- "./fabio.properties:/etc/fabio/fabio.properties"
consul:
image: consul
command: agent -config-file=/usr/local/etc/consul/server_agent.json
volumes:
- "./consul.json://usr/local/etc/consul/server_agent.json"
ports:
- "8500:8500"
web:
image: nginx
ports:
- "80:80"
environment:
- SERVICE_TAGS=urlprefix-/
- SERVICE_80_CHECK_HTTP=/
- SERVICE_80_NAME=web-app
- SERVICE_CHECK_INTERVAL=10s
- SERVICE_CHECK_TIMEOUT=5s
ip:
build:
context: ./
dockerfile: Dockerfile-ip
image: dalongrong/openresty-ip
skipper2:
image: dalongrong/skipper
environment:
- SERVICE_TAGS=urlprefix-/ip
- SERVICE_9090_NAME=skipper
- SERVICE_9090_CHECK_HTTP=/
- SERVICE_CHECK_INTERVAL=10s
- SERVICE_CHECK_TIMEOUT=5s
ports:
- "9090:9090"
volumes:
- "./router.eskip:/router.eskip"
command: skipper -enable-ratelimits -enable-prometheus-metrics -routes-file /router.eskip
registor:
image: gliderlabs/registrator:latest
command: consul://consul:8500
volumes:
- "/var/run/docker.sock:/tmp/docker.sock"
  • 说明
    对于skipper 的扩展使用的是nginx 重写,同时注册skipper到fabio中
    ip 服务的dockerfile && nginx 配置
    Dockerfile-ip
FROM openresty/openresty:alpine
COPY nginx.conf usr/local/openresty/nginx/conf/
EXPOSE 80

nginx.conf

worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
server {
listen 80;
server_name localhost;
charset utf-8;
location / {
rewrite ^/ip(.*) $1 break;
proxy_ignore_client_abort on;
client_body_buffer_size 10M;
client_max_body_size 10G;
proxy_buffers 1024 4k;
proxy_read_timeout 300;
proxy_pass http://localhost:88;
}
location /alert {
default_type text/html;
content_by_lua_block{
ngx.say([[<script>alert("error")</script>]])
}
} location /ip2 {
default_type text/html;
content_by_lua_block{
ngx.say(ngx.var.remote_addr)
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 88;
server_name localhost;
charset utf-8;
location / {
index index.html index.htm;
}
location /alert {
default_type text/html;
content_by_lua_block{
ngx.say([[<script>alert("error")</script>]])
}
} location /ip2 {
default_type text/html;
content_by_lua_block{
ngx.say(ngx.var.remote_addr.."from upstream")
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
  • fabio 配置文件
    fabio.properties
registry.consul.addr = consul:8500
  • skipper router 配置
hello: Path("/ip/*")->compress("text/html")-> corsOrigin()->setResponseHeader("TOKEN","dalongdemo")->responseCookie("test-session", "abc", 31536000)->
setRequestHeader("TOKEN","dalongdemo")-> "http://ip";
root: Path("/") -> status(200) -> <shunt>;

启动&&测试

  • 启动
docker-compose up -d

参考资料

https://github.com/rongfengliang/fabio-with-skipper
https://gliderlabs.github.io/registrator/latest/
https://github.com/fabiolb/fabio
https://github.com/zalando/skipper

 
 
 
 

使用skipper 扩展fabio 的路由&&http proxy 功能的更多相关文章

  1. Sails 关闭自动路由 Automatic Routes 功能。

    Sails 关闭自动路由 Automatic Routes 功能. Sails 中的路由两种:Custom Routes 和 Automatic Routes,自定义路由和自动路由.详见文档: Sai ...

  2. MVC小系列(二十一)【带扩展名的路由可能失效】

    mvc3之后:如果路由带上扩展名,比如这样: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRout ...

  3. SpringCloud:扩展zuul配置路由访问

    继续上次整合SpringCloud的demo进行扩展zuul:https://www.cnblogs.com/nhdlb/p/12555968.html  这里我把zuul划分出一个模块单独启动 创建 ...

  4. 爱上MVC系列~带扩展名的路由失效问题

    回到目录 对MVC中,对URL进行重写变得非常方便,你只要设置相应的路由规则即可完成,但进行MVC3后,发现设置了以下路由,系统具体不认 routes.MapRoute( name: "De ...

  5. MVC 带扩展名的路由无法访问

    在MVC中,路由是必不可少的,而且MVC对Url的重写非常方便,只需要在路由中配置相应的规则即可.假如我们需要给信息详情页配置路由,代码如下: routes.MapRoute( name: " ...

  6. 扩展XAF模型信息实现自定义功能

    如何隐藏 web listview 的 编辑控制列如下图: 这列怎么让它隐藏? 感谢[少侠]XAF_杨东 提供解答!感谢XAF_小学生整理.   A: 注册自定义接口IModelListViewExt ...

  7. MVC采用HtmlHelper扩展和Filter封装验证码的功能

    最近因为有个项目除了登录还有其他很多地方需要用到验证码的功能,所以想到了采用HtmlHelper和ActionFilter封装一个验证码的功能,以便能够重复调用.封装好以后调用很方便,只需在View中 ...

  8. [原创] 扩展jquery-treegrid插件, 实现勾选功能和全删按钮.

    新上手一个项目, 因而正好想学习下bootstrap, 所以就采用asp.net mvc + bootstrap来做.  因为需要TreeGrid的控件, 本来想用easyUI.LingerUi.DW ...

  9. WiFidog 广告路由可修改功能更加智能化的几点看法

    海蜘蛛Tomato出了mini版,这个对很多做WiFi营销的朋友来说,是一个福音,因为可以直接从FIR302B,一台30多块钱的路由直接刷成Hi-WiFi,而且界面这么漂亮 相信很多人已经对此界面OE ...

随机推荐

  1. SQL-25 获取员工其当前的薪水比其manager当前薪水还高的相关信息

    题目描述 获取员工其当前的薪水比其manager当前薪水还高的相关信息,当前表示to_date='9999-01-01',结果第一列给出员工的emp_no,第二列给出其manager的manager_ ...

  2. html页面技巧

    Query获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...});   //为S ...

  3. sac cut

    Put a perl script here in order to remind myself of its correct usage:

  4. Python 基础学习day1

    1.计算机的组成 CPU:相当于人的大脑,预算中心. 内存:临时加载数据或者程序. 缺点:断电即消失. 硬盘:存放所有的数据,输入输出设备. 2.什么是操作系统. 调控所有硬件与软件的中间介质. 3. ...

  5. maven搭建ssh项目及遇到的问题

    如果采用手动添加jar包的方式搭建项目,会使效率降低,传到github上时,下载时需要下载很多jar包,用maven管理项目可以提高效率 我在搭建maven项目时遇到了 1) java.lang.No ...

  6. 【Python】unittest-5

    #练习9: import unittest from selenium import webdriver import time class GloryRoad(unittest.TestCase): ...

  7. 【Python】Excel-4(样式设置)

    #练习: #封装一个ExcelUtil的模块(构造函数是excel的路径),里面提供封装的方法: #1 获取某个sheet对象 #2 打印所有sheet名称 #3 给某个sheet的某个单元格写入内容 ...

  8. Nginx 浏览器打开是下载状态

    location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_inf ...

  9. Python学习笔记第八周

    目录: 一.基础概念 1.动态导入模块 2.断言机制 3.SocketServer 二.作业 FTP服务器 三.单独注明 1.类中装饰器 2.进度条 一.基础概念 1.动态导入模块 有时在编程过程中, ...

  10. 3D 网页,webgl ,threejs 实例

    http://learningthreejs.com/blog/2013/04/30/closing-the-gap-between-html-and-webgl/ http://adndevblog ...