当我流浪时,端口80不会被转发

时间:2016-09-02 13:59:55

标签: vagrant

我得到这个输出,当我流浪,端口80没有转发,所以我将如何通过网络浏览器访问该网站

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/precise64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Setting the name of the VM: Homestead_default_1472822347316_22641
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!

帮助我,谢谢

2 个答案:

答案 0 :(得分:1)

vagrant init生成的默认Vagrantfile包含如何转发端口80的示例:

# config.vm.network "forwarded_port", guest: 80, host: 8080

只需取消注释此行并根据需要调整端口。

答案 1 :(得分:0)

Vagrant无法转发<1024的主机端口。

因此,如果您执行config.vm.network "forwarded_port", guest: 80, host: 80,它将无法正常工作。

您可以使用本地SSH隧道侦听主机上的端口80,并将流量转发到来宾上的端口80。

sudo ssh -p 2222 -gNfL 80:localhost:80 vagrant@localhost -i ~/.vagrant.d/insecure_private_key