IP:端口映射到名称
我在运行 WEBrick 的机架空间服务器上部署了多个 Rails 应用程序。它们每个都运行在不同的 TCP 端口上。
我可以使用 ptotem.com
(我的域名)访问端口 3000。
我可以使用 ptotem.com:3001
、ptotem.com:3002
... 访问其他应用程序,但我想使用 appl_one.ptotem 访问它们。 com
,app_two.ptotem.com
。
我怎样才能用 DNS 做到这一点?
I have deployed multiple rails apps on a rackspace server running WEBrick. Each of them runs on a different TCP port.
I can access port 3000 using ptotem.com
(my domain name).
I can access other apps using ptotem.com:3001
, ptotem.com:3002
..., but I would like to access them using appl_one.ptotem.com
, app_two.ptotem.com
.
How could I do this with DNS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你实际上不能这样做,DNS 命名机制和 TCP/IP 端口机制是两个独立的、不相关的实体,它们存在于 OSI 模型。如果您考虑一下
appl_one.ptotem.com:3000
,appl_one.ptotem.com:3001
和appl_one.ptotem.com:3002
是仍然有效,并且可以让您访问不同的应用程序。如果您的名称服务器和应用程序都支持 SRV 记录,您也许可以使用它们,但支持因为目前这种情况充其量是稀疏且脆弱的。
对于 HTTP 应用程序,您可以研究的另一件事是在同一端口上运行它们,并使用虚拟主机,例如 这个。
当我需要做这样的事情时,我通常将我的网卡设置为具有多个IP(或者添加更多网卡,如果它们不支持此功能),并让我的应用程序绑定到特定的IP,但老实说,为了在连接字符串末尾键入
:port
,您实际上需要这样做的情况非常罕见...You can't really do that, the DNS naming mechanism and the TCP/IP port mechanism are two seperate, unrelated entities, which exist on different layers of the OSI model. If you think about it
appl_one.ptotem.com:3000
,appl_one.ptotem.com:3001
andappl_one.ptotem.com:3002
are still valid and would let you access your different apps.You may be able to use SRV records if both your name server and your application support them, but support for this is currently sparse and flakey at best.
The other thing you could look into for HTTP applications is running them on the same port and using virtual hosts with something like this.
When I need to do stuff like this I usually set my NIC's to have multiple IP's (or add more NIC's if they don't support this) and have my apps bind to a specific IP, but honestly, it's very rare that you actually need to do it, for the sake of typing
:port
on the end of your connect strings...在 Linux 上,您需要在 /etc/hosts 文件中添加一行。
用于本地主机、测试等。
或专用网络
或公共
On linux, you need to add a line to your /etc/hosts file.
for local host, testing, etc.
or for private network
or public