From 752b78ce05ddd76ab69dfda6589b200e090cb1a3 Mon Sep 17 00:00:00 2001 From: saidimu apale Date: Wed, 1 Oct 2014 13:35:42 -0400 Subject: [PATCH 1/3] Websockets support Added `Upgrade` and `Connection` headers to the template to allow nginx to [upgrade a request](http://nginx.com/blog/websocket-nginx/). ``` proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; ``` These headers are only added if a `WEBSOCKETS` environment variable is defined. --- nginx.tmpl | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nginx.tmpl b/nginx.tmpl index 2f1eac4..e09a7a5 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -40,6 +40,7 @@ upstream {{ $host }} { {{ end }} } +{{ range $index, $value := $containers }} server { gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; @@ -54,7 +55,16 @@ server { # HTTP 1.1 support proxy_http_version 1.1; - proxy_set_header Connection ""; + + {{ /* Only add the websockets Upgrade headers if a WEBSOCKETS env var is set. */}} + {{ if $value.Env.WEBSOCKETS }} + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + {{ else }} + proxy_set_header Connection ""; + {{ end }} + } +{{ end }} } {{ end }} From 1162e14e795f95bb1145aa6a47d9a7f039679733 Mon Sep 17 00:00:00 2001 From: saidimu apale Date: Wed, 1 Oct 2014 13:46:37 -0400 Subject: [PATCH 2/3] Websockets support in README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 7d3e26d..b965360 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,12 @@ Then start any containers you want proxied with an env var VIRTUAL_HOST=subdomai Provided your DNS is setup to forward foo.bar.com to the a host running nginx-proxy, the request will be routed to a container with the VIRTUAL_HOST env var set. +### Websockets support + +To proxy a websockets container, add an env var WEBSOCKETS=1 + + $ docker run -e VIRTUAL_HOST=foo.bar.com -e WEBSOCKETS=1 ... + ### Multiple Ports If your container exposes multiple ports, nginx-proxy will default to the service running on port 80. If you need to specify a different port, you can set a VIRTUAL_PORT env var to select a different one. If your container only exposes one port and it has a VIRTUAL_HOST env var set, that port will be selected. From 1b0d9ed28ce93785baaa6353387dae393097b684 Mon Sep 17 00:00:00 2001 From: saidimu apale Date: Wed, 1 Oct 2014 14:31:40 -0400 Subject: [PATCH 3/3] Fixed comment syntax error --- nginx.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nginx.tmpl b/nginx.tmpl index e09a7a5..4db3a2f 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -56,7 +56,7 @@ server { # HTTP 1.1 support proxy_http_version 1.1; - {{ /* Only add the websockets Upgrade headers if a WEBSOCKETS env var is set. */}} + {{/* Only add the websockets Upgrade headers if a WEBSOCKETS env var is set. */}} {{ if $value.Env.WEBSOCKETS }} proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";