Akka HTTP 不允许来自 macOS 上的远程主机的传入连接

Akka HTTP not allowing incoming connections from remote hosts on macOS

我想试试下面的小例子:

object Webserver {
  def main(args: Array[String]) {

    implicit val system = ActorSystem("my-system")
    implicit val materializer = ActorMaterializer()
    // needed for the future flatMap/onComplete in the end
    implicit val executionContext = system.dispatcher

    val route =
      path("hello") {
        get {
          redirect(Uri("https://google.com"), StatusCodes.PermanentRedirect)
        }
      }

    val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)

    println(s"Server online at http://localhost:8080/\nPress RETURN to stop...")
    StdIn.readLine() // let it run until user presses return
    bindingFuture
      .flatMap(_.unbind()) // trigger unbinding from the port
      .onComplete(_ => system.terminate()) // and shutdown when done
  }
}

在 macOS 上从同一主机访问时,这非常有效。但是,当我远程访问主机时,无法访问akka webserver。

我已经检查了我的防火墙选项,并确认程序 java 允许传入连接。

还有一件可疑的事情:当我 运行 python -m SimpleHTTPServer 8080 时,我得到以下 window:

我在启动我的 akka 应用程序时没有得到这个 window。我是否必须实施自定义逻辑来请求许可或其他东西?

要启用对服务器的远程访问,您需要将服务器绑定到外部接口。要简单地绑定到所有接口,您可以将 host/IP 设置为 0.0.0.0,例如:

Http().bindAndHandle(route, "0.0.0.0", 8080)