首先我通过 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 文件中不可以设置带端口的响应吗?如果想设置带端口的映射该如何呢?
还是其他原因?
No, domain name resolution has nothing to do with ports.
You directly
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
Then visit
www.test.com:8899
Do not include a port in the host. Express listens to 80 and then forwards the host