IP 地址的别名?
我正在使用 Nginx 通过网络部署 Ruby 项目。访问该项目的 Web 界面的方式是使用端口 (192.168.1.113:3000) 访问服务器的 IP 地址。这是比较麻烦的。我如何使用 http://clock.local 等位置?
I'm deploying a Ruby project over a network with Nginx. The way you access the web-interface of the project is going to the server's IP address with the port (192.168.1.113:3000). This is rather cumbersome. How could I use a location such as http://clock.local?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常操作系统都有一个“hosts”文件,您可以在其中设置指向 IP 的名称。这就是指定“localhost”的地方(至少对我来说)。
无论如何,我认为你可以为那里的IP设置一个别名,但端口不起作用。我想您仍然需要手动指定它。所以它将是 http://alias:3000/。
Usually operating systems have a "hosts" file where you can set a name that points to an IP. That's where "localhost" is specified (at least for me).
Anyway, I think you can set an alias to the IP there, but the port won't work. I guess you'll still need to specify it manually. So it'll be http://alias:3000/.
不熟悉 nginx,但为什么不能只在 /etc/hosts (或 WINDIR/system32/drivers/etc/hosts)中添加一个条目来将 IP 地址解析为用户定义的别名?
Not familiar with nginx, but why can't you just add an entry into /etc/hosts (or WINDIR/system32/drivers/etc/hosts) to resolve the IP address to a user defined alias?
如果您只需要从一两台机器进行解析,只需将别名放入 /etc/hosts 中即可。否则,如果您有本地专用 DNS 服务器,则可以在其中添加所需的名称,以便 LAN 上的每个人都可以使用它。我还在端口 80 上构建了一个代理,这样您就不需要指定端口。 (假设该机器上的端口 80 尚未被使用。)
编辑:我收回那句话,如果 80 已被使用并不重要,您可以通过虚拟主机进行代理:
If you only need to to resolve from one or two machines, just put the alias in /etc/hosts. Otherwise, if you've got a local private DNS server, you can add your desired name there so that it's available to everybody on the LAN. I'd also build a proxy on port 80 so that you don't need to specify the port. (Assuming port 80 on that machine isn't already being used.)
Edit: I take that back, it does't matter if 80 is already being used, you can proxy by vhost: