Nginx Websocket Support


Fresh off the development branch and to your local dev box, Nginx has released Websocket proxy support within Nginx!  In case you’re unfamiliar with Websockets, this protocol is meant to extend our world of HTTP/1.1 by enabling full-duplex communications between a client and server. 

As I’ve been playing around with Node.js and Meteor as of late, here’s a brief tutorial for those that may be interested in adding Nginx infront of your node stack for load-balancing, static offloading, etc.

1) Update your nginx.conf, here’s a sample:

server {
    listen 80;
    # point the docroot to the public folder of your app
    root /var/web/meteor-apps/msgme/public;
    index index.html;

    server_name _;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;

2) Restart nginx and watch the logs for errors:

sudo pkill nginx ; sleep 2; sudo /usr/local/nginx/sbin/nginx; tail -f /usr/local/nginx/logs/error.log