How to access specific port in vagrant box laravel/homestead?

谁都会走 提交于 2019-12-11 13:24:48

问题


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

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.

My problem is, when I try to access project:8080 with my browser, I get a loading error.

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.

What can I do to make my webpack watcher work ?


回答1:


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'
    }

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.



来源:https://stackoverflow.com/questions/33454303/how-to-access-specific-port-in-vagrant-box-laravel-homestead

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!