大网数据广告活动
服务器运维问答

How do I forward websocket communication through an intermediary server?

· 52CE 我爱测

I'm trying to connect a websocket server (linux machine) and client (web browser) through an intermediary server (hosted on an AWS EC2 instance). The EC2 instance provides a public IP that the websocket server and client can refe…

问题原文

原帖链接 · Nick Sweet · CC BY-SA 3.0

I'm trying to connect a websocket server (linux machine) and client (web browser) through an intermediary server (hosted on an AWS EC2 instance). The EC2 instance provides a public IP that the websocket server and client can reference.

My client connects to ws://<SERVER>:<PORT>, where SERVER is the address of my EC2 instance and PORT is an arbitrary port I've opened for port forwarding (e.g. 9111).

On the websocket server, I'm running the following command:

  /usr/bin/ssh -f -N -i $KEY -l ubuntu \
                 -R $PORT:127.0.0.1:9090 \
                 -L 9090:$SERVER:$PORT \
                  $SERVER

Where $KEY is a private key for EC2 and 9090 is the port my websocket server uses. I've configured my EC2 instance's ssh daemon to enable gateway ports, and port forwarding is working just fine.

The issue comes when I try to start my websocket server -- I get an Address already in use error, because apparently I can't start a websocket server on a port that I'm forwarding. Isn't this a fairly standard thing to do? What am I doing wrong?

Thanks!

已采纳解答

原帖链接 · unilynx · CC BY-SA 3.0

Your '-L 9090' option to SSH is opening a listener on port 9090, which conflicts with your websocket server. The -R option should suffice, and the forwardd connection will be bi-directional, you don't need to set up a 'reverse route' with -L.

You may need to enable the GatewayPorts option on your EC2 SSH daemon to be allowed to set up ports using -R that accept connections from any IP, in addition to any firewall changes.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-07-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。