将我的域指向我的 node.js 实例
我拥有一台运行 whm / cpanel 的服务器,最近我一直在尝试使用 node.js。我有一个正在运行的小节点测试服务器,我想为其指定一个域。到目前为止,我一直在使用 whm 来创建帐户并处理域,但这是一个不同的场景,当有多个其他域指向其他域时,我对如何使域指向我的服务器上的某些内容知之甚少。我的服务器上同时有不同的东西。
谢谢
I own a server running whm / cpanel, and I have recently been experimenting with node.js. I have a little node test server running and i would like to point a domain at it. Up till now, I have been using whm to create accounts and deal with domains, but this is a different scenario, and I have little knowledge about how to make a domain point to something on my server when there are multiple other domains pointing to other different things on my server at the same time.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,我从来没有尝试过这个,但是您可以在 .htaccess 文件中使用重写规则并重写所有内容以转到运行 Node.js 服务器的端口 8000。
因此,首先,设置您的 Node.js 服务器以侦听端口 8000。
然后,像在 cpanel 中一样创建域,并在文档根目录中添加一个重写后的 .htaccess 文件:
这应该将所有内容在内部转发到端口 8000,其中Node.js 会处理它。但我不知道持久连接/网络套接字如何与此策略配合使用。在这些情况下,最好跳过 apache,直接访问服务器上的端口 8000。
来源:http://es.w3support.net/index.php?db =sf&id=59994
Ok, I have never tried this, but you could use a rewrite rule in a .htaccess file and rewrite everything to goto to port 8000 where you have your node.js server running.
So first, set up your node.js server to listen to port 8000.
Then, create your domain like normal in cpanel, and in the doc root add a .htaccess file with this rewrite:
That should just forward everything internally to port 8000 where node.js will take care of it. But I don't know how persistent connections / websockets will work with this strategy. It may be better to skip apache in those cases by going directly to the port 8000 on your server.
Source: http://es.w3support.net/index.php?db=sf&id=59994
这有点棘手,因为 cpanel 将使用 apache 来配置域,而 apache 毫无疑问已经占用了端口 80,所以你不能在 apache 和 node.js 之间共享端口 80。您将无法通过 cpanel 进行配置。
您可以将域指向您的服务器,并让节点侦听另一个端口,例如 8000。
然后转到 http://mydomain .com:8000/
因此 apache/cpanel 处理对端口 80 和 443 的请求,node 处理对端口 8000 的请求。
很可能在一台机器上运行多个 Web 服务器,但它们每个都需要自己的端口( )
This is a little bit tricky, since cpanel is going to use apache to configure the domains, and apache has already taken port 80 without a doubt, so you can't share port 80 between apache and node.js. You will not be able to configure this through cpanel.
You could just point the domain to your server and have node listen to another port such as 8000.
Then go to http://mydomain.com:8000/
So apache/cpanel handles requests to ports 80 and 443, and node handles requests to port 8000.
It is very possible to run multiple web servers on one box, but they each need their own port(s)
我设法这样做:
其他任何东西都对我不起作用:(
这里我检查端口是否不是3000,如果协议不是https,那么我将域指向端口3000(你可以把你使用的端口使用node.js)你可以删除
RewriteCond %{HTTPS} !=on
以防你不关心检查协议我在本地做了一些研发,但我相信我在生产中。将使用 nginx + node 而不是 apache。
I managed to do it like that:
Anything else didn't worked for me :(
Here I check if the port is not 3000 and if the protocol is not https then I point the domain to port 3000 (you can put the port you use with node.js) you can remove the
RewriteCond %{HTTPS} !=on
in case you don't care to check for the protocol.I do some R&D locally but in production I believe I will use nginx + node instead of apache.