简体   繁体   English

从主机连接流浪汉localhost:3000

[英]Connecting localhost:3000 in vagrant from host machine

How do I connect guest localhost:3000 from host machine? 如何从主机连接来宾localhost:3000?

So I have set up a Vue project in Vagrant. 因此,我在Vagrant中建立了一个Vue项目。 vagrant ssh in and serving the project by yarn dev and it shows that it's running on localhost:3000 in Vagrant. vagrant sshyarn dev人员为该项目提供服务,它表明该项目正在Vagrant中的localhost:3000上运行。

Here is my Homestead.yaml configuration: - map: consumer.test to: /home/vagrant/projects/Consumer 这是我的Homestead.yaml配置: - map: consumer.test to: /home/vagrant/projects/Consumer

On my host machine, I have added edited my hosts file as following: 192.168.10.10 consumer.test 在主机上,我添加了编辑的hosts文件,如下所示: 192.168.10.10 consumer.test

So I went to consumer.test on my host machine, but of course it won't run cus the port number is missing, and gives the following error: 403 Forbidden nginx/1.13.6 所以我去了我的主机上的consumer.test ,但是当然它不会运行,因为端口号丢失了,并给出了以下错误: 403 Forbidden nginx/1.13.6

How do I fix this? 我该如何解决?

Okay. 好的。 I just got it sorted. 我只是整理好了。

Step 1 第1步

First I have to forward the port number from guest(vagrant ssh) to host machine. 首先,我必须将端口号从guest(vagrant ssh)转发到主机。 This is done through Homestead.yaml configuration: 这是通过Homestead.yaml配置完成的:

d ports: - send: 80 (from host) - to: 3000 (to guest machine)

OR 要么

you can add this to your Vagrant config: config.vm.network "forwarded_port", guest: 3000, host: 80, auto_correct: true 您可以将此添加到您的Vagrant配置中: config.vm.network "forwarded_port", guest: 3000, host: 80, auto_correct: true

Step 2 第2步

I changed my C:\\Windows\\System32\\drivers\\etc\\hosts configuration from: 我从以下位置更改了C:\\Windows\\System32\\drivers\\etc\\hosts配置:

192.168.10.10 consumer.test

to

127.0.0.1 consumer.test

Step 3 第三步

As I'm using Vue (nuxt). 当我使用Vue(nuxt)时。 I added HOST=0.0.0.0 PORT=3000 in my package.json "scripts": { "dev": "HOST=0.0.0.0 PORT=3000 nuxt", "build": "nuxt build", "start": "nuxt start", "generate": "nuxt generate", "lint": "eslint --ext .js,.vue --ignore-path .gitignore .", "precommit": "npm run lint" }, 我在package.json添加了HOST=0.0.0.0 PORT=3000 "scripts": { "dev": "HOST=0.0.0.0 PORT=3000 nuxt", "build": "nuxt build", "start": "nuxt start", "generate": "nuxt generate", "lint": "eslint --ext .js,.vue --ignore-path .gitignore .", "precommit": "npm run lint" },

Now I just need to vagrant ssh in the project folder and run yarn dev . 现在,我只需要在项目文件夹vagrant ssh ,并运行yarn dev On the host machine now I can access it from consumer.test . 现在,在主机上,我可以从consumer.test访问它。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM