如何解决Apache Nutch 不公开其 API
我正在尝试使用 Apache Nutch 1.x Rest API。我使用 docker 镜像来设置 Nutch 和 Solr。您可以在 here
中查看演示存储库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 /admin
当我使用 Postman 或从浏览器尝试此操作时,它无法访问服务器并返回 500 错误。
但是,当我使用 docker exec -it
进入容器并尝试卷曲 localhost:8081/admin
时,我得到了正确的响应。因此,在容器内 API 已启动并运行,但不会对外公开。
在我的一次试用中,我在另一个容器中添加了一个前端应用程序,并将休息请求发送到 Solr 和 Nutch 容器。 Solr 成功了,Nutch 失败了 500。这告诉我,Nutch 容器不仅对外界无法访问,而且对同一网络内的容器也无法访问。
知道如何解决这个问题吗?
解决方法
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'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。