如果主机已侦听该端口,如何将其转发给无业游民的来宾 [英] How to forward a port to vagrant guest if this port already listened by host machine

查看:122
本文介绍了如果主机已侦听该端口,如何将其转发给无业游民的来宾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有一个应用程序,该应用程序动态运行无业游民的机器,并希望其中的某些信息将通过http发送到特定的主机端口.因此,我的应用监听指定的端口(http服务器),而我无法转发该端口:

For example I have an app which run vagrant machines dynamically and expect some info from them will be sent through http to specific host machine port. So, my app listening specified port (http server) and I can't forward that port:

C:\ node-vagrant-test-task>无用重新加载 ==>默认值:清除任何先前设置的转发端口... Vagrant无法转发此VM上的指定端口,因为它们会 与其他已经在监听这些应用程序的应用程序发生冲突 端口.到8080的转发端口已在主机上使用 机器.

C:\node-vagrant-test-task>vagrant reload ==> default: Clearing any previously set forwarded ports... Vagrant cannot forward the specified ports on this VM, since they would collide with some other application that is already listening on these ports. The forwarded port to 8080 is already in use on the host machine.

要解决此问题,请修改当前项目的Vagrantfile以使用其他 港口.例如,将"1234"替换为唯一的主机端口:

To fix this, modify your current project's Vagrantfile to use another port. Example, where '1234' would be replaced by a unique host port:

config.vm.network:转发端口,访客:8080,主机:1234

config.vm.network :forwarded_port, guest: 8080, host: 1234

有时,Vagrant会尝试为您自动更正此错误.在这个 案例,流浪汉无法做到.这通常是因为访客机 处于不允许修改端口转发的状态.你可以 尝试无用的重新加载"(等同于先暂停后再启动) 因此,流浪汉可以在引导时尝试自动更正此错误.被警告 任何未保存的工作都可能会丢失.

Sometimes, Vagrant will attempt to auto-correct this for you. In this case, Vagrant was unable to. This is usually because the guest machine is in a state which doesn't allow modifying port forwarding. You could try 'vagrant reload' (equivalent of running a halt followed by an up) so vagrant can attempt to auto-correct this upon booting. Be warned that any unsaved work might be lost.

推荐答案

如果您不想弄乱转发端口,最好的方法是为访客使用静态IP

If you do not want to mess with forwarding port, the best is to use a static IP for the guest

您可以使用静态IP进行专用或公用网络

you can do either private or public networks with a static IP

Vagrant.configure("2") do |config|
  config.vm.network "private_network", ip: "192.168.50.4"
end

Vagrant.configure("2") do |config|
  config.vm.network "public_network", ip: "192.168.50.4"
end

因此您无需转发8080端口即可直接在 http://192.168.50.4上访问您的应用:8080

so you dont need to forward the 8080 port and can access your app directly on http://192.168.50.4:8080

如果您随后需要访问此访客的主机,则可以通过192.168.50.1

If you need to then access the host machine for this guest, you can access it via 192.168.50.1

这篇关于如果主机已侦听该端口,如何将其转发给无业游民的来宾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆