如何访问无业游民的盒子laravel/homestead中的特定端口? [英] How to access specific port in vagrant box laravel/homestead?
问题描述
我正在我无所事事的laravel/homestead盒子上的节点项目上工作.
一切正常,当我进入/etc/hosts
中的主机定义时,我可以访问该项目:
I'm working on a node project on my vagrant laravel/homestead box.
Everything works fine, I can access the project when I go to the host define in my /etc/hosts
:
192.168.10.10 project
但是,我正在尝试使用webpack构建和观看我的项目,所以我安装了webpack-dev-server并可以运行它:
But, I'm trying to build and watch my project with webpack, so I installed webpack-dev-server and I can run it :
http://localhost:8080/
webpack result is served from /
content is served from /home/vagrant/Workspace/Kanban
404s will fallback to /index.html
[...]
webpack: bundle is now VALID.
我的问题是,当我尝试使用浏览器访问project:8080时,出现加载错误.
My problem is, when I try to access project:8080 with my browser, I get a loading error.
流浪汉中的netstat -an | grep 8080
告诉我盒子正在监听.
我尝试使用homestead.yaml
A netstat -an | grep 8080
in the vagrant shows me that the box is listening.
I tried to forward ports using homestead.yaml
ports:
- send: 8080
to: 8080
protocol: tcp
无论端口转发与否,我得到的只是一个错误页面.
But with or without port forwarding, all I get is an error page.
我该怎么做才能使Webpack观察器正常工作?
What can I do to make my webpack watcher work ?
推荐答案
好的,我终于找到了答案. 问题是关于端口而不是开发服务器.默认情况下,它配置为仅在本地主机上工作.解决方案是在配置中添加一条规则:
Okay, I finnaly found the answer. The problem was about not ports but the dev-server. It is configured by default to work only on the localhost. The solution was to add a rule to the configuration :
devServer : {
[...]
, host : '0.0.0.0'
}
将主机设置为'0.0.0.0'可以从任何地方访问dev-server,从而可以访问我的真实"主机. 我在 GitHub问题上找到了解释.遗憾的是,参数列表不在官方文档中.
Setting the host to '0.0.0.0' allows the dev-server to be accessible from anywhere, therefore, to my "real" host. I found the explanation on a GitHub issue. Too bad that the arguments list wasn't on the official documentation.
这篇关于如何访问无业游民的盒子laravel/homestead中的特定端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!