1

Websocket support is built in to Nginx as of 1.3.13, so I should have it.
Can someone please provide me the simplest example of a config that will allow my nginx (on Centos 6) proxy to accept an HTTP Connect from my client, then the proxy will establish a websocket connection to the backend on another server on behalf of the client and proxy communications between client and websocket server?

I have been trying for days and get only 400 errors. I would be very grateful.

I have tried:

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
              '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;
    server{
        listen  8080;
        listen  80;

        location /wsDemo?ID=12 {
            proxy_pass http://myserver.com:80/wsDemo?ID=12;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }

    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;
}
Lukas
  • 1,004
  • 6
  • 14
  • Nginx does not support the CONNECT HTTP method... The more you know! –  Mar 26 '13 at 12:45

1 Answers1

1

The point is, that location does not match query strings (the stuff behind the question mark).

You will have to use something like if:

    location /wsDemo {
        if($arg_ID = 12) {
            proxy_pass http://myserver.com:80/wsDemo?ID=12;
            break;
        }
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
Lukas
  • 1,004
  • 6
  • 14