aptible/docker-nginx — pull request #28 by fancyremarker (2014-11-26 20:44:17+00:00)
Title: Fork default (HTTP) config for Proxy Protocol proxy

cc: @aaw

This is the necessary configuration change to support #9, logging the original requester's IP address and passing it through a TCP-only Elastic Load Balancer to the NGiNX reverse proxy (without decrypting the HTTPS request).

The code change has been tested and works, but requires the additional configuration changes to the Elastic Load Balancer to enable Proxy Protocol:

```
elb create-load-balancer-policy --load-balancer-name $ELB_NAME --policy-name EnableProxyProtocol --policy-type-name ProxyProtocolPolicyType --policy-attributes AttributeName=ProxyProtocol,AttributeValue=True
elb set-load-balancer-policies-for-backend-server --load-balancer-name $ELB_NAME --instance-port $INSTANCE_HTTP_PORT --policy-names EnableProxyProtocol
elb set-load-balancer-policies-for-backend-server --load-balancer-name $ELB_NAME --instance-port $INSTANCE_HTTPS_PORT --policy-names EnableProxyProtocol
```

The BATS tests were harder to adapt. To simulate Proxy Protocol requests, I included HAProxy, the originators of the Proxy Protocol spec, who make it easy to configure Proxy Protocol. For some strange reason, it takes about 5 seconds for NGiNX to start responding to Proxy Protocol requests. In the meantime, requests just get dropped. This is \#NoMeGusta but \#YODOO (You Only DevOps Once).

One question I have is: should this be a separate branch (and Docker tag), as I've PRed it? Or should we branch on an environment variable, say `ENV['PROXY_PROTOCOL'] == 'true'`? I initially leaned toward a separate branch, because a Proxy Protocol proxy and an HTTP proxy are mutually incompatible; that is, a Proxy Protocol proxy cannot interpret plain HTTP(S) requests, and an HTTP proxy cannot interpret Proxy Protocol requests. I wish there was a way in NGiNX to check whether a request has Proxy Protocol headers, and only parse it as a Proxy Protocol request if so, but I can't see how to do that.