将Apache转发Websocket到Golang

huangapple go评论80阅读模式
英文:

Apache forward Websocket to Golang

问题

我的网站大部分是使用PHP和Apache进行交付的,运行得很好。
然而,我想在一个页面(或多个页面)上使用Websocket。
为了进行Websocket通信,我想使用golang。
为了不让客户端遇到任何防火墙问题,Websocket应该使用正常的Web端口。
(在这种情况下是443,用于Websocket的SSL版本)。

因为Apache已经在该端口上监听,我需要它将Websocket请求(或特定URL的请求)转发到我的golang程序。
(一个单独的golang程序必须监听所有传入的Websocket连接,以便它们之间可以轻松通信。)

有办法实现这个吗?

英文:

The most part of my website is delivered with PHP and Apache,
which works just fine.
However I want to use Websocket for a page (or multiple pages).
For the Websocket communication I want to use golang.
To not let the clients run into any firewall problems Websocket should use the normal webport.
(443 that is in this case - for the SSL version of Websocket).

Because Apache is already listening on that port, I need it to forward Websocket requests (or requests to a specific URL) to my golang program.
(A single golang program must listen to all incoming websocket connections, to allow for easy communication between them.)

Is there a way to achieve that?

答案1

得分: 1

一个Web服务器必须代理另一个服务器。所以你需要配置Apache将请求代理到你的Golang程序,或者在你的Golang程序中加入一个反向代理来处理Apache的内容。

配置Apache作为代理可能比将反向代理包含在你的Golang代码中更容易,但是有一个标准库可以实现这个功能:http://golang.org/pkg/net/http/httputil/

英文:

<p>one of the web servers must proxy for the other. So you need to either configure Apache to proxy requests to your Golang program, or incorporate a reverse proxy into your golang program to deal with the Apache content.</p>
<p>It's probably easier to configure Apache as a proxy than include the reverse proxy into your Golang code, but there is a standard lib for it: <a href="http://golang.org/pkg/net/http/httputil/">http://golang.org/pkg/net/http/httputil/</a></p>

huangapple
  • 本文由 发表于 2013年9月13日 18:55:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/18784605.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定