# Issue in configuring nginx for libwebsocket

**URL:** <https://www.ruby-forum.com/t/issue-in-configuring-nginx-for-libwebsocket/237021>\
**Category:** NGINX\
**Created:** [October 19, 2013, 4:10am UTC](https://www.ruby-forum.com/t/issue-in-configuring-nginx-for-libwebsocket/237021 "2013-10-19T04:10:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [October 19, 2013, 4:10am UTC](https://www.ruby-forum.com/t/issue-in-configuring-nginx-for-libwebsocket/237021/1 "2013-10-19T04:10:02Z")

</div>

Hi All

I am a newbie with nginx server. I am trying to get websocket  
configuration  
working on cent-os.(linux 2.6.32-358.18.1.el6.x86\_64). Following is my  
nginx config file;

http {  
include 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 logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
    listen 80;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
        root html;
        index index.html index.htm;
       * proxy_pass http://localhost:80*;
        proxy_http_version 1.1;
        *proxy_set_header Upgrade $http_upgrade;*

```

- 

```
       proxy_set_header Connection "upgrade";*

```

- 

```
       proxy_set_header Host $host;*
      proxy_read_timeout 3600;
      proxy_send_timeout 3600;
  }

  #error_page 404 /404.html;
   location / {

```

# root html;

# index index.html index.htm;

# }

#}

# HTTPS server

# 

#server {

# listen 443;

# server\_name localhost;

# ssl on;

# ssl\_certificate cert.pem;

# ssl\_certificate\_key cert.key;

# ssl\_session\_timeout 5m;

# ssl\_protocols SSLv2 SSLv3 TLSv1;

# ssl\_ciphers HIGH:!aNULL:!MD5;

# ssl\_prefer\_server\_ciphers on;

# location / {

# root html;

# index index.html index.htm;

# }

#}

}

With above configuration, and with proxy\_pass set, it gices 502 error.  
When  
I try to access  
ws://127.0.0.1:80 using chrome websocket client.

I will highly appreciate if someone can give right pointer to resolving  
this.

Thanks a ton

Hemant

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [October 19, 2013, 4:34am UTC](https://www.ruby-forum.com/t/issue-in-configuring-nginx-for-libwebsocket/237021/2 "2013-10-19T04:34:00Z")

</div>

I changed the configuration to :

location /hello {  
hello;  
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;  
proxy\_pass [http://localhost:80](http://localhost:80);  
proxy\_http\_version 1.1;  
proxy\_set\_header Upgrade $http\_upgrade;  
proxy\_set\_header Connection “upgrade”;  
proxy\_set\_header Host $host;  
}

With a helllo module compiled in and when I send the GET request with  
upgrade connection for protocol swicth,  
although I do not get 502 error for BAD\_GATEWAY but I end up having  
normal  
200k instead of  
protocol switch 101 response.

Please suggest, where I am going wrong.

Thanks  
Hemant

On Fri, Oct 18, 2013 at 7:09 PM, Hemant K.
