node-http-proxy does not support websockets on node 0.10.x

tl;dr: I’m annoyed that node-http-proxy has been broken for a long time in a non-obvious way,  and I’ve ditched it in favor of nginx.

For about two years, I’ve been serving content from Amazon EC2 and from my home FiOS connection that was proxied by a simple reverse proxy built on node-http-proxy. During the last few months, I’ve had intermittent trouble with apps that use websockets, specifically through socket.io.  (Notably etherpad and tty.js)

This has caused me much grief. Last night I spent hours debugging this, ultimately discovering that, as of today, node-http-proxy does not support websockets when running on node 0.10.x.

I like using node.  It’s generally fun.  But debugging this issue, only to discover that it’s been a known issue for several months, was very frustrating.  Moreover, there is a fix in the works – a branch called ‘caronte‘ – but the API changes so significantly that I cannot quickly port my proxy to the refactored library, because the entire “proxy table” functionality is gone.

My expedient solution was to install nginx.  Nginx has supported websockets since Feb 2013, and while it didn’t work out-of-the-box, it was not hard to configure.  Here’s a snippet from my /etc/nginx/sites-available/default:


                proxy_set_header X-Real-IP $remote_addr;                                               
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;                           
                proxy_set_header Host $http_host;                                                      
                proxy_set_header X-NginX-Proxy true;                                                   

                # prevents 502 bad gateway error                                                       
                proxy_buffers 8 32k;                                                                   
                proxy_buffer_size 64k;                                                                 
                # enables WS support                                                                   
                proxy_http_version 1.1;                                                                
                proxy_set_header Upgrade $http_upgrade;                                                
                proxy_set_header Connection "upgrade";                                                 
                proxy_redirect off;                                                                    

        location / {                                                                                   
                proxy_pass http://localhost:81;                                                        
        }                                                                                              

        location /term/ {                                                                              
                proxy_pass http://127.0.0.1:8001/;                                                     
        }                                                                                              

        location /hackflowy/ {                                                                         
                proxy_pass http://127.0.0.1:3000/;                                                     
        }                                                    
    
        # others follow

2 thoughts on “node-http-proxy does not support websockets on node 0.10.x

Leave a Reply

Your email address will not be published.