Akka HTTP不允许来自macOS上远程主机的传入连接
我想尝试以下小示例:Akka HTTP不允许来自macOS上远程主机的传入连接,macos,scala,akka,akka-http,Macos,Scala,Akka,Akka Http,我想尝试以下小示例: 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 execut
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 Web服务器
我已经检查了防火墙选项,并验证程序java
是否允许传入连接
还有一件可疑的事情:当我运行python-msimplehttpserver 8080时,我会看到以下窗口:
启动akka应用程序时,我没有看到此窗口。我是否必须实现自定义逻辑来请求权限或其他什么?要启用对服务器的远程访问,需要将服务器绑定到外部接口。要简单地绑定到所有接口,可以将主机/IP设置为
0.0.0.0
,如:
Http().bindAndHandle(route, "0.0.0.0", 8080)
要启用对服务器的远程访问,需要将服务器绑定到外部接口。要简单地绑定到所有接口,可以将主机/IP设置为
0.0.0.0
,如:
Http().bindAndHandle(route, "0.0.0.0", 8080)