Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
        listen  8080;
        listen  80;

        location /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
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_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
share|improve this answer

Your Answer


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