送终是什么意思| 上火喝什么茶效果最好| 体寒的女人吃什么能调理好身体| 学分是什么意思| 什么叫全日制本科| 脖子发麻是什么原因| 白芷炖肉起什么作用| 险象环生是什么意思| 什么水果是温性的| 一个人自言自语的说话是什么病| 成佛是什么意思| 雪人是什么生肖| 壮志凌云是什么生肖| 室性早搏吃什么药| 猛吸气胸口疼什么原因| 牛奶什么时候喝好| 梦见好多鱼是什么意思| 1996是什么年| 蚯蚓可以钓什么鱼| 霸凌是什么意思| 月亮为什么会发光| alb是什么意思| 赶的偏旁是什么| 胆囊切除后可以吃什么水果| 前列腺炎是什么原因引起的| 劳改犯是什么意思| 蒙氏结节是什么| 什么是cosplay| 减肥早餐吃什么好| 湿热是什么原因引起的| 唐老鸭叫什么名字| 招财进宝是什么生肖| 孕期血糖高可以吃什么水果| 247是什么意思| 皂基是什么| 痔疮为什么会出血| 驼鸟吃什么食物| 天秤座和什么座最配对| 排卵日有什么症状| 没出息什么意思| bv是什么品牌| est.是什么意思| 口疮吃什么药| 早上4点是什么时辰| 过敏性皮炎吃什么药好| 工作室是干什么的| 45属什么| 感冒去医院挂什么科| 用什么消肿最快最有效方法| 牙疼吃什么药效果最好| 尾牙宴是什么意思| 孤独症有什么表现| jewelry什么意思| 补体c4偏低是什么意思| 双肾钙化灶是什么意思| 去威海玩需要准备什么| 雯字五行属什么| 乳头胀痛什么原因| 预防医学是什么| 果五行属什么| 梦到死去的亲人是什么意思| 木牛流马是什么意思| 抬旗是什么意思| 为什么月经期有性冲动| 耳朵不舒服是什么原因| 胸透检查什么| 被老鼠咬了打什么疫苗| 甲减什么症状| 下午右眼跳是什么预兆| 女性气血不足吃什么调理| 3月11日是什么星座| 势在必得是什么意思| 脸红是什么大病的前兆| 检查全身挂什么科| 鱼喜欢什么颜色| 深海鱼油有什么功效| 5月24日什么星座| 惟字五行属什么| 什么蔬菜含维生素d| 湿疹吃什么药| 双向情感障碍是什么| 彩超跟b超有什么区别| 嘴巴里甜甜的是什么原因| hpv感染有什么症状女性| 鸡蛋吃多了有什么危害| 头皮疼是什么原因引起的| 做凉粉用什么淀粉最好| 沈字五行属什么| 一花一世界下一句是什么| 妒忌是什么意思| 2024年五行属什么| 脱轨是什么意思| 桑榆未晚是什么意思| 狗狗打疫苗前后要注意什么| 抗心磷脂抗体是什么| 梦见已故母亲预示什么| 不是一路人是什么意思| 小孩睡觉流鼻血是什么原因引起的| 一什么野菜| 贝加台念什么| 脂蛋白高是什么原因| 品牌是什么意思| 昆明有什么好吃的| KH是什么| 下午5点到7点是什么时辰| 外阴白斑是什么病| 梦见自己出嫁是什么意思| 渐入佳境是什么意思| 人为什么会放屁| 腿发软无力是什么原因引起的| 环状肉芽肿是什么皮肤病| 脚发麻是什么原因| 澳门的货币叫什么| 屁特别多是什么原因| 挖苦是什么意思| 种什么药材最快又值钱| 菱角是什么| 海带和什么不能一起吃| 白芨有什么作用和功效| 函询是什么意思| 妙赞是什么意思| 晚上睡觉阴部外面为什么会痒| rh是什么单位| 戛然而止是什么意思| 网调是什么意思| 什么地发现| kissme什么意思| 雌二醇是什么| 辅弼是什么意思| 立棍是什么意思| bulova是什么牌子的手表| 什么叫副乳| 庄周梦蝶是什么意思| 偷鸡不成蚀把米是什么意思| 四月十号是什么星座| 低钠盐是什么意思| 什么是眩晕症| 胎膜是什么| 阴道口瘙痒是什么原因| 猪油吃多了有什么好处和坏处| 尿毒症是什么症状| 精神焦虑症有什么表现有哪些| 左眼皮老是跳是什么原因| 轰趴是什么意思| 21金维他有什么作用| 生吃大蒜有什么好处| 老舍为什么自杀| 安徽菜属于什么菜系| 省委委员是什么级别| 菩提是什么| 夏天吃什么菜最好| 强迫症是什么| 什么叫动脉硬化| 殉情是什么意思| 不什么而什么| 冬季吃什么| 七月二十二什么日子| 什么的妈妈| 鞭尸是什么意思| pbc是什么意思| 肠易激综合征吃什么药好| 例假血是黑色的是什么原因| 蚯蚓中药叫什么| 为什么鞋子洗了还是臭| 吃洋葱对身体有什么好处| 淼淼是什么意思| 排卵期为什么会出血| 前列腺液是什么样子| 淘宝预售是什么意思| 为什么乳头内陷| 什么是双一流| 什么叫邪淫| creative是什么意思| 壤土适合种植什么植物| 神经紊乱会出现什么症状| 经期不能吃什么| 火车和高铁有什么区别| 心血管科是看什么病| 药流没流干净有什么症状| 尿道口流脓吃什么药| 桑叶泡水喝有什么功效| 狮子男和什么星座最配| 光是什么| 头发竖起来是什么原因| 吃完避孕药有什么反应| 白脉病西医叫什么病| 三叉神经痛吃什么药效果最好| 热得什么| 高血压是什么引起的| 哪吒妈妈叫什么名字| 性冷淡吃什么药| 梦见蛇和鱼是什么意思周公解梦| 睡觉口干舌燥什么原因| 红茶适合什么季节喝| 病灶什么意思| 吐露是什么意思| 洗手指征是什么| 平均血小板体积偏低是什么原因| 眼压高是什么原因造成的| 夜尿频多吃什么药效果好| 月经不停吃什么药止血效果比较好| 低血糖平时要注意什么| 支气管炎性改变是什么意思| 三sprit是什么牌子| 五什么十什么成语| 27属相是什么生肖| 肝阴不足吃什么中成药| 左腿疼是什么原因| 根有什么作用| 什么是援交| 氩气是什么气体| 豆汁是什么味道| 什么叫扁平疣长什么样| nac是什么意思| 炙什么意思| 吉加页读什么| 六月二十五号是什么星座| 坊字五行属什么| 碱什么意思| 梦见情敌什么预兆| 什么是速率| 氧化铜什么颜色| 琳琅是什么意思| 舌头烂了是什么原因| 眼睛干痒滴什么眼药水| 蚊子咬了为什么会痒| 坐月子什么不能吃| 为什么不要看电焊火花| 天外有天人外有人是什么意思| 精液长什么样| 嘴子是什么意思| 人类什么时候出现的| 靠谱什么意思| 心阳不足吃什么中成药| 男生为什么要做包皮手术| 金钱骨是什么部位| 感冒为什么会咳嗽| 沙僧是什么生肖| 海阔什么| 巨蟹座是什么象| 5.16号是什么星座| 羡慕不来是什么意思| 吃生南瓜子有什么好处| 长期失眠吃什么药| 孕早期适合吃什么食物| 春梦是什么意思啊| 道是什么意思| 一什么草坪| 吃什么发胖最快| 阴道流黄色分泌物是什么原因| 毕婚族是什么意思| 小孩磨牙是什么原因| 孕妇可以喝什么饮料| 儿童铅超标有什么症状| ozark是什么牌子| 孩子不说话挂什么科| 下面痒吃什么消炎药| 人体最大的器官是什么| 脾切除后有什么影响| 痹是什么意思| 窦骁的父母是干什么的| 雪五行属什么| 甲减喝什么药| 什么火锅最好吃| 百度
Skip to content

martensson/nixy

Repository files navigation

nixy release Build Status Go Report Card license

nginx gopher

Nixy is a daemon that automatically configures Nginx for web services deployed on Apache Mesos and Marathon.

Features:

  • Reverse proxy and load balancer for your microservices running inside Mesos and Marathon
  • Single binary with no other dependencies (except Nginx/Openresty)
  • Written in Go to be blazingly fast and concurrent.
  • All the features you would expect from Nginx:
    • HTTP/TCP/UDP load balancing, HTTP/2 termination, websockets, SSL/TLS termination, caching/compression, authentication, media streaming, static file serving, etc.
  • Zero downtime with Nginx fall-back mechanism for sick backends and hot config reload.
  • Easy to customize your needs with templating.
  • Statistics via statsd (successful/failed updates, timings).
  • Real-time updates via Marathon's event stream (Marathon v0.9.0), so no need for callbacks.
  • Support for Marathon HA cluster, auto detects sick endpoints.
  • Automatic service discovery of all running tasks inside Mesos/Marathon, including their health status.
  • Basic auth support.
  • Health checks for errors in template, nginx config or Marathon endpoints.
  • Built-in Prometheus exporter for metrics and alerts.
  • ....

Compatibility

  • All versions of Marathon >= v0.9.0
  • All versions of Nginx or OpenResty (Also possible to run inside Docker).

Getting started

  1. Install nixy from pre-compiled packages. Check releases page.

  2. Edit config (default on ubuntu is /etc/nixy.toml):

    # Nixy listening port
    port = "6000"
    # X-Proxy header, defaults to hostname
    xproxy = ""
    
    # Marathon API
    marathon = ["http://example01:8080", "http://example02:8080"] # add all HA cluster nodes in priority order.
    user = "" # leave empty if no auth is required.
    pass = ""
    # Nixy realm, set this if you want to be able to filter your apps (e.g. when you have different loadbalancers which should expose different apps)
    # You will also need to set "NIXY_REALM" label at your app to be included in generated conf
    realm = ""
    
    # Nginx
    nginx_config = "/etc/nginx/nginx.conf"
    nginx_template = "/etc/nginx/nginx.tmpl"
    nginx_cmd = "nginx" # optionally "openresty" or "docker exec nginx nginx"
    nginx_ignore_check = false # optionally disable nginx config test. Health check will always show OK.
    #left_delimiter = "{{" # if you want to change the default template delimiters
    #right_delimiter = "}}" # if you want to change the default template delimiters
    
    # Statsd settings
    [statsd]
    addr = "localhost:8125" # optional for statistics
    #namespace = "nixy.my_mesos_cluster"
    #sample_rate = 100
  3. Optionally edit the nginx template (default on ubuntu is /etc/nginx/nginx.tmpl)

  4. Install nginx or openresty and start the service.

    • Or if you prefer running inside Docker: "docker run -d --name nginx -p 7000:7000 -v /etc/nginx:/etc/nginx nginx". You will also need to change config "nginx_cmd" to "docker exec nginx nginx" for reloads to work correctly in this case.
  5. Start nixy! (service nixy start)

Using Nixy

Routing is based on the HTTP Host header matching app ID by default.

If apps are organized under a directory structure the directory will become the root subdomain.

This is easy to change and customize to your own choosing by editing the nginx.tmpl file. For example if you prefer routing based on uri instead of subdomains take a look at nginx-path.tmpl.

Example to access your apps /bar1, /bar2, /foo/bar3 running inside Mesos and Marathon:

curl -i localhost/ -H 'Host: bar1.example.com'
curl -i localhost/ -H 'Host: bar2.example.com'
curl -i localhost/ -H 'Host: bar3.foo.example.com'

Assuming you have configured nginx on port 80.

To set a custom subdomain for an application

Deploy your app to Marathon setting a custom label called subdomain:

"labels": {
    "subdomain": "foobar"
},

This will override the Host for that app and replace it with foobar as the new subdomain/host.

It's also possible to add multiple subdomains to a single app, dividing by a space character.

"labels": {
    "subdomain": "foo bar"
},

This will now match both foo and bar as the new subdomain/host.

Template

Nixy uses the standard Go (Golang) template package to generate its config. It's a powerful and easy to use language to fully customize the nginx config. The default template is meant to be a working base that adds some sane defaults for Nginx. If needed just extend it or modify to suite your environment the best.

If you are unsure of what variables you can use inside your template just do a GET /v1/config and you will receive a JSON response of everything available. All labels and environment variables are available. Other options could be to enable websockets, HTTP/2, SSL/TLS, or to control ports, logging, load balancing method, or any other custom settings your applications need.

HTTP Load Balancing / Proxy

Examples:

Add some ACL rules to block traffic from outside the internal network? Add a Label called internal to your app and the following snippet to your template:

{{- if $app.Labels.internal}}
# allow anyone from local network.
allow 10.0.0.0/8;
# block everyone else
deny all;
{{- end }}

Optionally, add dynamically which network that have access to the same label:

{{- if $app.Labels.internal}}
# allow anyone from local network.
allow {{ $app.Labels.internal }};
# block everyone else
deny all;
{{- end }}

Add a custom http header based on an Environment variable inside your app?

{{- if $app.Env.APP_ENV}}
# could be dev, stage, production...
add_header X-Environment {{ $app.Env.APP_ENV }} always;
{{- end}}

Additional template methods

contains

Wrapper for strings.Contains. Contains reports whether substr is within string.

{{if contains $host "www" }}
hasPrefix

Wrapper for strings.HasPrefix. HasPrefix tests whether the string s begins with prefix.

{{if hasPrefix $host "www" }}
hasSuffix

Wrapper for strings.HasSuffix. HasSuffix tests whether the string s ends with suffix.

{{if hasSuffix $host ".com" }}
split

Wrapper for strings.Split. Splits the input string on the separating string and returns a slice of substrings.

{{- $url := split "localhost:8080" ":" }}
    host: {{index $url 0}}
    port: {{index $url 1}}
join

Alias for the strings.Join function.

apps: {{join $applist ","}}
trim

Alias for the strings.Trim function.

host: {{trim ".app.test.com." "."}}
replace

Alias for the strings.Replace function.

{{$host := "app/test/com"}}
host = {{replace $host "/" "." -1}}
getenv

Wrapper for os.Getenv. Retrieves the value of the environment variable named by the key. It returns the value, which will be empty if the variable is not present.

hostname: {{getenv "HOSTNAME"}}
datetime

Alias for time.Now

# Generated by nixy {{datetime}}

MergeAppsByLabel

Sometimes it is useful to implement the same service with apps within marathon. In this case you can use .MergeAppsByLabel("some-label") instead of .Apps in your template to merge multiple apps into a single service.

For example if the following apps running in marathon implement the same API:

my-service-a my-service-b

And they both have the label servicename=my-service you could use MergeAppsByLabel("servicename") to access both implementations as nixy.marathon.mesos:12345.

  • When the apps are merged, Labels from each original app are added to each Task from that original app. This is necessary if you want to have implementation specific labels. For example, if one implementation is faster, we could route more traffic there.

TCP/UDP Load Balancing / Proxy

It is possible to use Nixy to configure nginx as a proxy for TCP or UDP traffic.

Please check the nginx-stream.tmpl example template. It assumes you have configured PortDefinitions correctly for all your services in Marathon.

Latest versions of Nginx open-source comes with streaming by default. If you are running version 1.9 you will need to compile it with --with-stream manually.

Nixy API

  • GET / prints nixy version.
  • GET /v1/config JSON response with all variables available inside the template.
  • GET /v1/reload manually trigger a new config reload.
  • GET /v1/health JSON response with health status of template, nginx config and Marathon endpoints available.
  • GET /v1/metrics Prometheus metrics endpoint.

Nagios Monitoring

In case you want to monitor nixy using Nagios (or compatible monitoring) you can use the included check_nixy plugin.

About

nixy - nginx auto configuration and service discovery for Mesos/Marathon

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 8

为什么叫印度阿三 什么品种荔枝最好吃 中国第一个不平等条约是什么 有什么书 举世无双什么意思
流汗有什么好处 海灵菇是什么 车标是牛的是什么车 妇科支原体感染吃什么药 zara是什么品牌
甲状旁腺是什么意思 什么是脑死亡 假牙什么材质的最好 构树是什么树 朝鲜和韩国是什么关系
11月2号是什么星座 疣体是什么 尿失禁是什么症状 低血糖吃什么水果 补充蛋白质吃什么最好
胆汁反流是什么意思hcv8jop9ns8r.cn 潮喷是什么意思hcv8jop6ns1r.cn 25周岁属什么生肖hcv7jop9ns8r.cn 怀孕建卡需要什么材料hcv8jop5ns9r.cn 电动车电池什么牌子好hcv7jop6ns2r.cn
布洛芬缓释胶囊有什么副作用huizhijixie.com 肝囊肿是什么原因引起的xjhesheng.com 什么是褪黑素hcv9jop0ns9r.cn 过生日送什么礼物hcv7jop6ns7r.cn 亚洲没有什么气候adwl56.com
血小板减少是什么原因hcv7jop9ns2r.cn 1.8号是什么星座luyiluode.com 1和0是什么意思hcv9jop6ns7r.cn 左肾小结石是什么意思hcv9jop4ns8r.cn 产妇吃什么鸡最好tiangongnft.com
营养性贫血是什么意思mmeoe.com 小孩说梦话是什么原因引起的huizhijixie.com 考虑黄体是什么意思hcv7jop5ns0r.cn 电音是什么意思beikeqingting.com 参乌健脑胶囊适合什么人吃hcv9jop0ns1r.cn
百度