远程监听 Akka-HTTP 端口

Listening to Akka-HTTP ports remotely

使用 Akka-HTTP 绑定对端口 9000 的调用时

Http().bindAndHandle(routes, "localhost", 9000)

它开始监听 'netstat -tulpn'

所见的端口
Proto  Recv-Q  Send-Q  Local Address   Foreign Address  State   
tcp6   0       0       127.0.0.1:9000  :::*             LISTEN   

本地可以使用这个端口。 但是,当我进行远程调用时,我得到:

curl: (7) Failed to connect to 169.254.0.2 port 9000: Connection refused

即使可以 ping 通并且设备直接连接。我究竟做错了什么?

localhost 替换为 0.0.0.0 即可。 localhost 仅供本地使用。

您需要绑定IP地址:

Http().bindAndHandle(routes, "169.254.0.2", 9000)

只听本地主机接口是一个好习惯。在生产使用中,您应该通过代理(nginx 或 apache)

捕获来自 public 接口的请求