user644745
user644745

Reputation: 5723

socket.io slow response after using nginx

I have used my local setup without nginx to serve my node.js application, I was using socket.io and the performance was quite good.

Now, I am using nginx to proxy my request and I see that socket.io has a huge response time, which means my page is getting rendered fast, but the data rendered by socket.io is order of magnitude slower than before.

I am using NGINX 1.1.16 and here is the conf,

gzip  on;

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    access_log  logs/host.access.log  main;

    location / {
        proxy_pass http://localhost:9999;
        root   html;
        index  index.html index.htm;
    }

Even though everything is working, I have 2 issues,

  1. socket.io response is slower than before. With NGINX, the response time is around 12-15sec and without, it's hardly 300ms. tried this with apache benchmark.

  2. I see this message in the console, which was not there before using NGINX,

    [2012-03-08 09:50:58.889] [INFO] console -    warn  - 'websocket connection invalid'
    

Upvotes: 4

Views: 5234

Answers (3)

Chuan Ma
Chuan Ma

Reputation: 9914

Nginx only supports websocket starting from 1.3.13. It should be straightforward to set it up. Check the link below:

http://nginx.org/en/docs/http/websocket.html

Upvotes: 0

Kief
Kief

Reputation: 4493

You could try adding:

proxy_buffering off;

See the docs for info, but I've seen some chatter on various forums that buffering increases the response time in some cases.

Upvotes: 6

ming_codes
ming_codes

Reputation: 2922

Is the console message from NGINX or SocketIO?

NGINX proxy does not talk HTTP 1.1, which may be why web socket is not working.

Update: Found a blog post about it: http://www.letseehere.com/reverse-proxy-web-sockets

A proposed solution: http://blog.mixu.net/2011/08/13/nginx-websockets-ssl-and-socket-io-deployment/

Upvotes: 0

Related Questions