Can I map a hostname *and* a port with /etc/hosts? [closed]

微笑、不失礼 提交于 2019-11-26 23:56:09

问题


Can I map an IP address like 127.0.0.1 to a domain name and a port?

For example, I would like to map 127.0.0.1 to api.example.com:8000


回答1:


No, that's not possible. The port is not part of the hostname, so it has no meaning in the hosts-file.




回答2:


If you really need to do this, use reverse proxy.

For example, with nginx as reverse proxy

server {
  listen       api.mydomain.com:80;
  server_name  api.mydomain.com;
  location / {
    proxy_pass http://127.0.0.1:8000;
  }
}


来源:https://stackoverflow.com/questions/10729034/can-i-map-a-hostname-and-a-port-with-etc-hosts

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