You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This module wraps node's various `Server` interfaces so that they are compatible with the [PROXY protocol](http://haproxy.1wt.eu/download/1.5/doc/proxy-protocol.txt). It automatically parses the PROXY headers and resets `socket.remoteAddress` and `socket.remotePort` so that they have the correct values.
5
+
6
+
npm install proxywrap
7
+
8
+
This module is especially useful if you need to get the client IP address when you're behind an AWS ELB in TCP mode.
9
+
10
+
In HTTP or HTTPS mode (aka SSL termination at ELB), the ELB inserts `X-Forwarded-For` headers for you. However, in TCP mode, the ELB can't understand the underlying protocol, so you lose the client's IP address. With the PROXY protocol and this module, you're able to retain the client IP address with any protocol.
11
+
12
+
In order for this module to work, you must [enable the PROXY protocol on your ELB](http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/enable-proxy-protocol.html) (or whatever proxy your app is behind).
13
+
14
+
Usage
15
+
-----
16
+
17
+
proxywrap is a drop-in replacement. Here's a simple Express app:
18
+
19
+
var http = require('http')
20
+
, proxiedHttp = require('proxywrap').proxy(http)
21
+
, express = require('express')
22
+
, app = express()
23
+
, srv = proxiedHttp.createServer(app); // instead of http.createServer(app)
The magic happens in the `proxywrap.proxy()` call. It wraps the module's `Server` constructor and handles a bunch of messy details for you.
32
+
33
+
You can do the same with `net` (raw TCP streams), `https`, and `spdy`. It will probably work with other modules that follow the same pattern, but none have been tested.
34
+
35
+
*Note*: If you're wrapping [node-spdy](https://github.com/indutny/node-spdy), its exports are a little strange:
36
+
37
+
var proxiedSpdy = require('proxywrap').proxy(require('spdy').server);
38
+
39
+
**Warning:***All* traffic to your proxied server MUST use the PROXY protocol. If the first five bytes received aren't `PROXY`, the connection will be dropped. Obviously, the node server accepting PROXY connections should not be exposed directly to the internet; only the proxy (whether ELB, HAProxy, or something else) should be able to connect to node.
0 commit comments