search

Home  >  Q&A  >  body text

node.js - mac下,修改hosts 无效的问题!路过的大腿帮忙看一下吧

首先我通过 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 文件中不可以设置带端口的响应吗?如果想设置带端口的映射该如何呢?
还是其他原因?

黄舟黄舟2863 days ago835

reply all(4)I'll reply

  • 高洛峰

    高洛峰2017-04-17 15:43:03

    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.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 15:43:03

    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.

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 15:43:03

    • 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

    reply
    0
  • 黄舟

    黄舟2017-04-17 15:43:03

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

    reply
    0
  • Cancelreply