【问题标题】:How to proxy forward ttyd using Apache如何使用 Apache 代理转发 ttyd
【发布时间】:2019-10-24 02:51:34
【问题描述】:

ttyd 是一个很好的基于网络的终端: https://github.com/tsl0922/ttyd

默认使用7681端口,所以配置成功后可以在浏览器中从localhost:7681访问终端。

我们在端口 80 上有由 Apache 提供支持的 Web 服务器,并且只有这个端口对 Internet 开放。所以为了访问ttyd,我想设置一个代理转发localhost/shelllocalhost:7681,我在httpd.conf中设置如下:

<VirtualHost *:80>
    ProxyPass /shell http://127.0.0.1:7681/
    ProxyPassReverse /shell http://127.0.0.1:7681/
</VirtualHost>

当我访问localhost/shell 时,它向我显示了带有“连接已关闭”消息的 ttyd 页面。似乎连接不成立。如何解决这个问题?

【问题讨论】:

标签: apache reverse-proxy portforwarding tty


【解决方案1】:

这里的问题是你需要代理两个协议,即httpws(WebSocket)。如果没有对后者进行特定处理,Apache 将(当然)将前者用于所有不起作用的事情。

如果您查看ttyd 日志并在浏览器中打开http://127.0.0.1:7681/,您可以观察到这种行为(使用不同的协议)。相反,在原来的两个Proxy* 指令到位的情况下,打开浏览器的Web 控制台并访问http://127.0.0.1/shell/ 显示所有对“[/]ws”的请求都失败,而ttyd 将只记录http 对所有内容的请求(包括“ [/]ws")。

以下解决了这个问题(注意这需要mod_proxy_wstunnelmod_rewrite):

    RewriteEngine on
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule /shell/?(.*) "ws://127.0.0.1:7681/$1" [P,L]
    ProxyPass /shell/ http://127.0.0.1:7681/
    ProxyPassReverse /shell/ http://127.0.0.1:7681/

【讨论】:

    【解决方案2】:

    启用 wstunnel 扩展的 Apache,在代理设置中:

    ProxyPass /webash/ws ws://127.0.0.1:7681/ws
    ProxyPass /webash http://127.0.0.1:7681/
    ProxyPassReverse /webash http://127.0.0.1:7681/
    

    在 Ubuntu 14.04 中测试,使用安全凭证启动:

    ./ttyd_linux.x86_64 -c Somebody:SuperPassword bash > /dev/null 2>&1 &
    

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 1970-01-01
      • 2017-11-06
      • 2013-06-04
      • 2012-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-03
      相关资源
      最近更新 更多