node.js - mac下,修改hosts 无效的问题!路过的大腿帮忙看一下吧
黄舟
黄舟 2017-04-17 15:41:03
0
4
790

首先我通过 express 监听 8899 端口,在浏览器可以通过127.0.0.1:8899 访问本地服务,然后我希望在浏览器输入 www.test.com 达到一样的目的, 因此我在 hosts 文件做了对应修改

127.0.0.1:8899 www.test.com

但是并没有效果,通过 ihost 或者 chrome 插件修改同样无效,

但是我在 hosts 文件做如下的修改却是有效的

127.0.0.1 www.baidu.com // 此时百度无法访问

127.x.x.33 www.test.com // 此时 设置 test 对应某远端地址生效

是因为 hosts 文件中不可以设置带端口的响应吗?如果想设置带端口的映射该如何呢?
还是其他原因?

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(4)
小葫芦

No, domain name resolution has nothing to do with ports.

You directly

127.0.0.1 www.test.com

Then access www.test.com:8899 and that’s it. If you don’t want the backend to have port access, just listen to 80 yourself first, and then do the forwarding.

大家讲道理

Ports cannot be set in the hosts file, only IP. You need to forward your local access to the domain name www.test.com from ip to ip:port. As for how to operate it on MAC, please search it yourself.

刘奇
  • The hosts file ignores the port number

So you can only configure one

127.0.0.1 www.test.com

Then visit www.test.com:8899

黄舟

Do not include a port in the host. Express listens to 80 and then forwards the host

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template