Rad1
Rad1

Reputation: 215

Cowboy forward to port

I am working on a web-socket project and i want web-socket cowboy server to listen to 8080 port but to forward messages to another port . Can I do that ? any help is appreciated

Upvotes: 1

Views: 892

Answers (1)

ash
ash

Reputation: 711

what do you mean by forward messages to another port? cowboy's handler is handling the messages that arrive on your websocket. You can take those an redirect them anywhere you like. However I think what you are really after is a proxy that fronts your cowboy. If that is the case you should consider nginx as a front. Once you installed it you can provide this config:

 http {
   ...
        server {
           listen 443
           ...

           location ~ ^/myws/
           {
             proxy_pass                      http://127.0.0.1:8080 ;
             proxy_http_version              1.1 ;
             proxy_set_header                Upgrade     $http_upgrade ;
             proxy_set_header                Connection  "upgrade" ;

             proxy_connect_timeout           60 ;
             proxy_read_timeout              86400 ;
             proxy_send_timeout              86400 ;
             proxy_ignore_client_abort       off ;
             proxy_redirect                  off ;
           }
          ...
        }
   ....
 }

this will enable you to run cowboy listening on any port you like (8080 in your example) while letting nginx take care of you SSL needs while forwarding websocket requests to cowboy. The client can connect @

wss://{your server}/myws

If you do not need SSL address will be

ws://{your server}/myws

and listen port in the config above needs to change to 80.

Upvotes: 2

Related Questions