Access node.js/grunt server through localhost:port on virtual machine

筅森魡賤 提交于 2019-12-17 23:05:40

问题


I'm running a node.js server locally on port 9000 through Grunt. I also have a virtual machine running (vmware), but I can't access the node server through that. I've already configured the VM to access my Apache server on the host through localhost, but :9000 gives 'not found'.

Anyone know how to do this?


回答1:


Got it! In my project's Grunt.js file there was this setting:

grunt.initConfig({
    ...
    connect: {
      options: {
        port: 9000,
        // Change this to '0.0.0.0' to access the server from outside.
        hostname: 'localhost'
      },
    }
    ...
  });

All I had to do was to change localhost to 0.0.0.0 and restart grunt server.




回答2:


You have to use your local IP address.

I am on a mac so I go to System Preferences > Network > "Advanced" tab > TCP/IP > IPv4 Address: (ex 10.0.0.3)

Then point your browser to that address using your port number (ex :9000) or whatever you have setup.

Ex: http://10.0.0.3:9000

I don't think this is very secure for your local box so make sure to kill the server when you are finished working. Hope this helps.



来源:https://stackoverflow.com/questions/19583238/access-node-js-grunt-server-through-localhostport-on-virtual-machine

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