NGINX dynamic reverse proxying using Lua
I was looking for interesting stuff and found a project called hipache from dotcloud written in node.js. I start wondering if was possible to rebuild it using nginx + lua but as it turns out , it was already made by Sam Alba from dotcloud as hipache-nginx.
The hunt for more information lead me to a post on dotcloud blog explaining that they switched from the node.js version to nginx + lua and the reasons behind it, that made even more interested on this project.
While building a lab to check it out, I found a few isues with the current version that prevented it from running.
First issue was related to regular expression quoting.
So to fulfil my ‘interesting stuff’ addiction, I’ve forked the original project.
On the regular expression issue, I’ve changed the code to use lua’s find function, according to agenthz tweet, it’s faster for simple regular expressions than match.
As a workaround for the second issue I’ve made hipache-nginx mark backends as unavailable instead of announcing in pubsub for another process to catch.
Currently a small caveat is that a node will not return to alive state once marked as unavailable.
I’ve also changed the file structure of the project in a way that I felt more clean to implement future features, mostly cosmetics.
You can see this fork at https://github.com/caquino/hipache-nginx.
If you want to setup a lab too and don’t want to go through the hassle of building nginx with lua; I’ve quickly baked some ubuntu packages to help.
Again guys: if you know any company needing a Senior DevOps, willing to sponsor my relocation, drop me a message!