【问题标题】:play framework listen on localhost在 localhost 上播放框架监听
【发布时间】:2015-03-14 04:11:48
【问题描述】:

是否可以在 localhost 上启动 play framework 2.3 ?我试过了

./activator run -Dhttp.address=127.0.0.1 -Dhttp.port=9007

./activator run -Dhttp.address=localhost -Dhttp.port=9007 # From 

另一个stackoverflow线程 ./activator start -Dhttp.address=127.0.0.1 -Dhttp.port=9007

但每次我收到都没有任何效果

[info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9007

相关话题Force Play Framework to listen on localhost only

【问题讨论】:

    标签: scala playframework playframework-2.3


    【解决方案1】:

    根据 Play Framework 提供的documentation,您所采用的方式仅适用于基于 Netty 的 Play 实例。我假设您正在使用 Akka-Http,但是如果您不是,请将此作为错误报告给 Play Framework 团队。

    您可能还想阅读this,它介绍了如何将 Play Framework 设置为在 Nginx 或 Apache 等代理之后工作。

    最后一件事,通常建议只将绝对必要的端口暴露给外部互联网,以防止攻击者利用您系统中可能存在的弱点。我建议你,不管你是否能正常工作,还要在你的盒子上安装一些好的 IPTables 软件并阻止你的本地端口,在防火墙后面,Play 实例正在运行。

    【讨论】:

      【解决方案2】:

      而不是: ./activator run -Dhttp.address=127.0.0.1 -Dhttp.port=9007

      反转参数(“运行”之前的“-D”选项):

      activator -Dhttp.address=127.0.0.1 run

      --- (Running the application, auto-reloading is enabled) ---
      [info] p.c.s.NettyServer - Listening for HTTP on /127.0.0.1:9007
      (Server started, use Ctrl+D to stop and go back to the console...)
      

      【讨论】:

        【解决方案3】:

        只需执行activator "run 9007"(假设activator 在您的PATH 中,这是常态)。

        另见:

        【讨论】:

        • 它改变了端口,但不改变主机。
        【解决方案4】:

        试试这个

        ./activator "运行 9007"

        您可以通过 localhost 访问您的应用程序。你可以写任何你想要的端口来代替 9007

        【讨论】:

        • 默认监听 0.0.0.0 。我真的需要 127.0.0.1
        • 环回地址是一个特殊的IP号码(127.0.0.1),指定用于机器的软件环回接口。试试这个链接stackoverflow.com/a/20778887/1478261
        • 0.0.0.0 表示我的站点可以从外部访问,127.0.0.1 表示只有本地服务可以连接到它。我的播放框架在 ngnix 代理后面,我想避免从互联网直接访问播放 - 我可以使用 iptables 来完成,但似乎是一种更简单的方法。
        • 那我觉得IP表是更好的选择。
        猜你喜欢
        • 2017-03-03
        • 1970-01-01
        • 2017-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多