Go websocket,nginx代理是正确的吗?

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

Go websocket, nginx proxy is this correct?

问题

我有一个使用Go语言编写的RESTful服务器,它在nginx后面。目前一切都很好,我们对这个设置(nginx和Go)很满意,但现在我们为这个应用程序添加了一个websocket路由(目前在我们的测试服务器上使用nginx工作正常,但还没有真正的负载)。

问题:

  1. 我的websocket路由也放在nginx后面好吗?有没有什么好的理由支持或反对这样做?

  2. 有没有办法绕过nginx代理直接使用Go来提供此路由?而不是使用另一个子域名或另一个二进制文件。

谢谢!

英文:

I have a RESTful server in go, and it's behind nginx. everything is fine and we are happy with this setup (nginx and go) but now we have a websocket route for this application. (Its currently works ok with nginx in our staging server, not real load yet.)
The questions :

  1. Is this good for my websocket route to be behind nginx too? is there any good reason for/against this?

  2. Is there any way to bypass this route from nginx proxy and serve it directly with go? not in another subdomain or another binary.

Thanks!

答案1

得分: 1

我不是nginx专家,但鉴于没有其他人回答,我将提供一些我的研究结果。

1)是的,nginx绝对是一个不错的选择。你可以在这里找到一些基准测试。可能的注意事项在这篇(较旧的)文章中提到。最重要的考虑因素是超时方面。这两个 答案在这方面提供了有用的信息。

2)不太确定你想通过这样做实现什么,但你可以简单地使用不同的端口,因为WebSockets不受同源策略的限制,或者使用上面一个答案中描述的TCP转发模块。

英文:

I am no nginx expert but given that nobody else has answered I will present some of my research.

  1. Yes, nginx is definitely a good choice for that. You can find some benchmarks here. Possible caveats are mentioned in this (older) post. The most important point to consider is the timeout aspect. These two answers give helpful information in that regard.

  2. Not exactly sure what you want to achieve by that but you could simply use a different port, as websockets are not subject to the same origin policy, or use the tcp forwarding module that is described in one of the answers above.

huangapple
  • 本文由 发表于 2015年6月28日 01:16:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/31091390.html
匿名

发表评论

匿名网友

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

确定