RedWire Reverse Proxy
A dynamic, high performance, load balancing reverse proxy.
A reverse proxy accepts web requests and dispatches these out to other web servers based on the host header. This is identical to Apache's mod_proxy and nginx's proxy_pass.
RedWire can replace nginx in many situations.
RedWire supports:
- HTTP
- HTTPS / SSL through SNI (sorry IE6)
- websockets over http and https
- changing configuration at runtime
- custom functions (middleware)
- Node.js v0.12 / iojs
Install
npm install redwire
RedWire only depends on the excellent node-http-proxy and has been heavily inspired by the fantastic redbird reverse proxy.
Examples
var RedWire = ;var redwire = // more configuration is available, see below http: port: 80 ; // proxy requests for example.com to port 3000 locallyredwire;// a shorthand form is availableredwire; // proxy to another server with a different host header// paths can be used as part of the proxy, longer paths are matched firstredwire ; // paths can also be used on the destinationredwire; // some helpful middleware has been providedredwire;redwire;redwire; // you can write your own middlewareredwire ; // a single middleware can be used for an entire domainexample = redwire ;// additional 'matches' can be registeredexample;example; // balance load across several serversload = redwire ;redwire ;// adjust servers at runtimeload;
Configuration
// defaults are shownvar RedWire = ;var options = http: port: 8080 websockets: no https: no proxy: xfwd: yes prependPath: no keepAlive: no log: {} {} { if errstack console; else console; } ;var redwire = options;
HTTP Configuration
When websockets are enabled use redwire.httpWs
to setup routes and middleware for websocket requests.
RedWire is often most useful handing request on port 80. If this is required your NodeJs application will need to run as root.
HTTPS Configuration
SNI (multiple ssl certificates) is supported by Internet Explorer 7 and above.
// a default certificate is requiredvar RedWire = ;var options = https: port: 443 key: 'path/to/key.pem' cert: 'path/to/cert.pem' ca: 'path/to/ca.pem (optional)' ;var redwire = options; // additional certificates can be added per host (optional)redwirecertificates; redwire;
Proxy Configuration
var RedWire = ;var options = proxy: prependPath: no xfwd: yes ;var redwire = options;
The whole options.proxy structure is passed to node-http-proxy so any options can be passed through. This for experts as changing things may interfere with RedWire's operation. A list of node-http-proxy options is available.
Use Cases
RedWire is a perfect replacement for nginx to dispatch requests to NodeJs servers. Here are other use cases:
- HTTP/SSL server - use RedWire to expose insecure websites and APIs secure on the internet.
- Authentication - add authentication checks in front of your generated APIs.
- Logging and Diagnostics - all requests can be logged with simple middleware, use RedWire to diagnose web issues.
- API Aggregation - pull together many different APIs at different URLs into one uniform URL for your users. e.g. api.company.com or company.com/api.
- Dynamic Load Balancing - add and remove servers from your pool at runtime. Hook up etcd or consul and load balance automatically.
At MetOcean we're using RedWire in all these situations.
Are you using RedWire for something that isn't on this list? Let us know!
TODO
- Tests for https
- Tests for ws
- Tests for removing dispatch nodes