{"id":1245,"date":"2013-11-15T13:04:56","date_gmt":"2013-11-15T18:04:56","guid":{"rendered":"https:\/\/risacher.org\/jfdi\/?p=1245"},"modified":"2016-08-23T11:48:56","modified_gmt":"2016-08-23T15:48:56","slug":"node-http-proxy-does-not-support-websockets-on-node-0-10-x","status":"publish","type":"post","link":"https:\/\/risacher.org\/jfdi\/2013\/11\/node-http-proxy-does-not-support-websockets-on-node-0-10-x\/","title":{"rendered":"node-http-proxy does not support websockets on node 0.10.x"},"content":{"rendered":"<p><em>tl;dr:<\/em> I&#8217;m annoyed that <a title=\"node-http-proxy\" href=\"https:\/\/github.com\/nodejitsu\/node-http-proxy\">node-http-proxy<\/a> has been broken for a long time in a non-obvious way,\u00a0 and I&#8217;ve ditched it in favor of <a href=\"http:\/\/nginx.org\/\">nginx<\/a>.<!--more--><\/p>\n<p>For about two years, I&#8217;ve been serving content from Amazon EC2 and from my home FiOS connection that was proxied by a <a title=\"my reverse-proxy\" href=\"https:\/\/risacher.org\/jfdi\/2013\/10\/my-reverse-proxy\/\">simple reverse proxy<\/a> built on <a title=\"node-http-proxy\" href=\"https:\/\/github.com\/nodejitsu\/node-http-proxy\">node-http-proxy<\/a>. During the last few months, I&#8217;ve had intermittent trouble with apps that use websockets, specifically through <a title=\"socket.io\" href=\"http:\/\/socket.io\/\">socket.io<\/a>.\u00a0 (Notably <a title=\"etherpad\" href=\"http:\/\/etherpad.org\/\">etherpad <\/a>and <a title=\"node.js-based ajax terminal emulator\" href=\"https:\/\/github.com\/chjj\/tty.js\/\">tty.js<\/a>)<\/p>\n<p>This has caused me much grief. Last night I spent hours debugging this, ultimately discovering that, as of today, <a title=\"node-http-proxy issue #444\" href=\"https:\/\/github.com\/nodejitsu\/node-http-proxy\/issues\/444\">node-http-proxy does not support websockets when running on node 0.10.x<\/a>.<\/p>\n<p>I <strong>like<\/strong> using node.\u00a0 It&#8217;s generally fun.\u00a0 But debugging this issue, only to discover that it&#8217;s been a known issue for several months, was very frustrating.\u00a0 Moreover, there is a fix in the works &#8211; a branch called &#8216;<a title=\"branch of http-proxy for node 0.10.x\" href=\"https:\/\/github.com\/nodejitsu\/node-http-proxy\/tree\/caronte\">caronte<\/a>&#8216; &#8211; but the API changes so significantly that I cannot quickly port my proxy to the refactored library, because the entire &#8220;proxy table&#8221; functionality is gone.<\/p>\n<p>My expedient solution was to install <a title=\"nginx\" href=\"http:\/\/nginx.org\/\">nginx<\/a>.\u00a0 Nginx has supported websockets since Feb 2013, and while it didn&#8217;t work out-of-the-box, it was not hard to configure.\u00a0 Here&#8217;s a snippet from my <code>\/etc\/nginx\/sites-available\/default<\/code>:<\/p>\n<pre><code>\r\n                proxy_set_header X-Real-IP $remote_addr;                                               \r\n                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                           \r\n                proxy_set_header Host $http_host;                                                      \r\n                proxy_set_header X-NginX-Proxy true;                                                   \r\n\r\n                # prevents 502 bad gateway error                                                       \r\n                proxy_buffers 8 32k;                                                                   \r\n                proxy_buffer_size 64k;                                                                 \r\n                # enables WS support                                                                   \r\n                proxy_http_version 1.1;                                                                \r\n                proxy_set_header Upgrade $http_upgrade;                                                \r\n                proxy_set_header Connection \"upgrade\";                                                 \r\n                proxy_redirect off;                                                                    \r\n\r\n        location \/ {                                                                                   \r\n                proxy_pass http:\/\/localhost:81;                                                        \r\n        }                                                                                              \r\n\r\n        location \/term\/ {                                                                              \r\n                proxy_pass http:\/\/127.0.0.1:8001\/;                                                     \r\n        }                                                                                              \r\n\r\n        location \/hackflowy\/ {                                                                         \r\n                proxy_pass http:\/\/127.0.0.1:3000\/;                                                     \r\n        }                                                    \r\n    \r\n        # others follow\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>tl;dr: I&#8217;m annoyed that node-http-proxy has been broken for a long time in a non-obvious way,\u00a0 and I&#8217;ve ditched it in favor of nginx.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5,11,10],"tags":[],"class_list":["post-1245","post","type-post","status-publish","format-standard","hentry","category-blogging","category-it","category-oss","category-personal"],"_links":{"self":[{"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/posts\/1245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/comments?post=1245"}],"version-history":[{"count":5,"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/posts\/1245\/revisions"}],"predecessor-version":[{"id":1250,"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/posts\/1245\/revisions\/1250"}],"wp:attachment":[{"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/media?parent=1245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/categories?post=1245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/risacher.org\/jfdi\/wp-json\/wp\/v2\/tags?post=1245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}