英文:
Go websocket, nginx proxy is this correct?
问题
我有一个使用Go语言编写的RESTful服务器,它在nginx后面。目前一切都很好,我们对这个设置(nginx和Go)很满意,但现在我们为这个应用程序添加了一个websocket路由(目前在我们的测试服务器上使用nginx工作正常,但还没有真正的负载)。
问题:
-
我的websocket路由也放在nginx后面好吗?有没有什么好的理由支持或反对这样做?
-
有没有办法绕过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 :
-
Is this good for my websocket route to be behind nginx too? is there any good reason for/against this?
-
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.
-
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.
-
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论