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

2019-03-07 18:45发布

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

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

Thanks!

2条回答
看我几分像从前
2楼-- · 2019-03-07 19:06

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

查看更多
Summer. ? 凉城
3楼-- · 2019-03-07 19:09

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;
  }
}
查看更多
登录 后发表回答