# Websocket proxy

**URL:** <https://www.ruby-forum.com/t/websocket-proxy/228821>\
**Category:** NGINX\
**Created:** [May 9, 2013, 12:36am UTC](https://www.ruby-forum.com/t/websocket-proxy/228821 "2013-05-09T00:36:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alder\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71c47a/32.png) [@Alder\_N](https://www.ruby-forum.com/u/Alder_N)\
**Post date:** [May 9, 2013, 12:36am UTC](https://www.ruby-forum.com/t/websocket-proxy/228821/1 "2013-05-09T00:36:29Z")

</div>

This must have been discussed before but I am new to nginx  
and this forum.

I am upgrading to 1.4 to use its websocket proxy feature.  
Say I have a websocket server running at port 81, so I want  
to forward all websocket packets to port 81, and process  
the rest at port 80.

Somehow the following conf doesn’t work, anything missing?

server {  
listen [::]:80 ipv6only=off;

```
    location / {
        regular_http_processing_directive;

        if ($http_upgrade = "websocket") {
            proxy_pass http://localhost:81;
        }

        proxy_http_version 1.1;
        proxy_set_header Upgrade websocket;
        proxy_set_header Connection upgrade;
    }

```

}

- Alder

---

<div class="post-metadata">

**Author:** ![Alder\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71c47a/32.png) [@Alder\_N](https://www.ruby-forum.com/u/Alder_N)\
**Post date:** [May 9, 2013, 8:20pm UTC](https://www.ruby-forum.com/t/websocket-proxy/228821/2 "2013-05-09T20:20:17Z")

</div>

At the http level:

map $http\_upgrade $connection\_upgrade {  
default upgrade;  
‘’ close;  
}

map $connection\_upgrade $proxy\_upstream\_port {  
upgrade 81;  
close 80;  
}

Then at the location do:

location / {  
proxy\_http\_version 1.1;  
proxy\_set\_header Upgrade $http\_upgrade;  
proxy\_set\_header Connection $connection\_upgrade;  
proxy\_pass [http://localhost](http://localhost):$proxy\_upstream\_port;  
}

Partly taken from [WebSocket proxying](http://nginx.org/en/docs/http/websocket.html).

----appa

---

<div class="post-metadata">

**Author:** ![Alder\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/71c47a/32.png) [@Alder\_N](https://www.ruby-forum.com/u/Alder_N)\
**Post date:** [May 9, 2013, 11:51pm UTC](https://www.ruby-forum.com/t/websocket-proxy/228821/3 "2013-05-09T23:51:45Z")

</div>

Thanks for the recipe.

Just tried and now I am not able to get regular  
HTTP working on port 80.

Has anybody ever got nginx websocket proxy working?

Thanks,

- Alder
