【问题标题】:Apache Nutch doesn't expose its APIApache Nutch 不公开其 API
【发布时间】:2021-06-12 13:45:56
【问题描述】:

我正在尝试使用 Apache Nutch 1.x Rest API。我使用 docker images 来设置 Nutch 和 Solr。你可以在here看到demo repo

Apache Nutch 使用 Solr 作为其依赖项。 Solr 效果很好,我可以通过localhost:8983 访问它的 GUI。

但是,我无法通过localhost:8081 访问 Apache Nutch 的 API。问题从这里开始。 Apache Nutch 1.X RESTAPI doc 表示我可以这样启动服务器 2. :~$ bin/nutch startserver -port <port_number> [If the port option is not mentioned then by default the server starts on port 8081]

我在 docker-compose.yml 文件中所做的事情。 我还将端口暴露在外面。

    ports:
       - "8080:8080"
       - "8081:8081"

但我无法从我的计算机上成功调用 API。

其余的 API 文档说,如果我向 /admin 端点发送 get 请求,我会得到响应。

GET /admin

当我使用 Postman 或浏览器尝试此操作时,它无法连接到服务器并返回 500 错误。

但是,当我使用 docker exec -it 进入容器并尝试 curl localhost:8081/admin 时,我得到了正确的响应。因此,在容器内 API 已启动并运行,但不会暴露在外部。

在我的一次试用中,我在另一个容器中添加了一个前端应用程序,并将休息请求发送到 Solr 和 Nutch 容器。 Solr 工作,Nutch 失败 500。这告诉我,Nutch 容器不仅外部无法访问,而且同一网络中的容器也无法访问。

知道如何解决这个问题吗?

【问题讨论】:

    标签: docker docker-compose nutch


    【解决方案1】:

    nutch默认只回复localhost的请求:

    bash-5.1# /root/nutch/bin/nutch startserver -help
    usage: NutchServer [-help] [-host <host>] [-port <port>]
     -help          Show this help
     -host <host>   The host to bind the Nutch Server to. Default is
                    localhost.
    

    因此,您需要以-host 0.0.0.0 开头,以便能够从主机或其他容器访问它:

    services:
      nutch:
        image: 'apache/nutch:latest'
        command: '/root/nutch/bin/nutch startserver -port 8081 -host 0.0.0.0'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-08-04
      • 2013-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多