Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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;
}
share|improve this question
    
What have you tried? –  Michael Hampton Mar 15 '13 at 16:03
    
Nginx does not support the CONNECT HTTP method... The more you know! –  user160910 Mar 26 '13 at 12:45
add comment

1 Answer

up vote 0 down vote accepted

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";
    }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.