# Whats is the correct message sequence for nginx server?

**URL:** <https://www.ruby-forum.com/t/whats-is-the-correct-message-sequence-for-nginx-server/246500>\
**Category:** NGINX\
**Created:** [October 23, 2013, 8:16pm UTC](https://www.ruby-forum.com/t/whats-is-the-correct-message-sequence-for-nginx-server/246500 "2013-10-23T20:16:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [October 23, 2013, 8:16pm UTC](https://www.ruby-forum.com/t/whats-is-the-correct-message-sequence-for-nginx-server/246500/1 "2013-10-23T20:16:31Z")

</div>

I am running nginx-1.5 server and sending chrome browser simple  
websocket  
request. My nginx server is confgiured with hello module which is  
supposed  
to send “Hello world” in response.

As per RFC for websocket, a sever is supposed to send "switching  
protocol  
message "as ACK for connection upgrade request message.  
In my wireshark capture, I do see connection upgrade request message but  
in  
response, I see HTTP 1.1 200 0K message with “Hello World”  
text on data portion of HTTP payload.

I am confused in terms of response, thinking my nginx server should have  
first sent connection upgrade response acknowledgement before responding  
with text data. Can anyone please suggest the right behaviour of nginx  
server when it gets a Connection upgrade request message.

My NGinx config is :  
server {  
listen 80;

```
    #access_log /var/log/nginx/access.log;
    #error_log /var/log/nginx/error.log;

    server_name localhost;

    # prevents 502 bad gateway error
    large_client_header_buffers 8 64k;

    location /hello {
            hello;
            #root html;
            #index index.html index.htm;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For

```

$proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_set\_header X-NginX-Proxy true;

```
            # prevents 502 bad gateway error
            proxy_buffers 8 32k;
            proxy_buffer_size 64k;
            proxy_connect_timeout 90;
            proxy_send_timeout 90;
            proxy_intercept_errors on;
            proxy_buffering on;
            proxy_busy_buffers_size 64k;
            proxy_temp_file_write_size 256k;
            proxy_read_timeout 300;

            #proxy_pass http://backend;
            proxy_redirect off;

            # enables WS support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
    }
}

```

Also when I enable #proxy\_pass [http://backend](http://backend) , server stop responding  
and  
gives HTTP1.1/400 bAD REQUEST saying  
cookie size is large. I am unable to understand , why enabling this line  
leads to this error , when the request is same in both the cases.

Any help will be appreciated?

Thanks  
Hemant

Posted at Nginx Forum:

> **[Whats is the correct message sequence for nginx server?](https://forum.nginx.org/read.php?2,244050,244050#msg-244050)**
>
> I am running nginx-1.5 server and sending chrome browser simple websocket request. My nginx server is confgiured with hello module which is supposed to send "Hello world" in response. As per RFC for websocket, a sever is supposed to send...

---

<div class="post-metadata">

**Author:** ![hemant\_psu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b77776/32.png) [@hemant\_psu](https://www.ruby-forum.com/u/hemant_psu)\
**Post date:** [October 23, 2013, 11:28pm UTC](https://www.ruby-forum.com/t/whats-is-the-correct-message-sequence-for-nginx-server/246500/2 "2013-10-23T23:28:48Z")

</div>

Hello!

On Wed, Oct 23, 2013 at 02:15:48PM -0400, hemant\_psu wrote:

> I am confused in terms of response, thinking my nginx server should have  
> first sent connection upgrade response acknowledgement before responding  
> with text data. Can anyone please suggest the right behaviour of nginx  
> server when it gets a Connection upgrade request message.

You can’t make an arbitrary nginx module to talk via WebSocket  
protocol, this isn’t going to work.

What you can is to use nginx to proxy WebSocket connections to  
some WebSocket backend server using proxy\_pass, as documented  
here:

> **[WebSocket proxying](http://nginx.org/en/docs/http/websocket.html)**

Note that you need an actual backend server handling WebSocket  
connections for proxying to work.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**
