运行弹性搜索服务器时。我们可以访问www.example.com:9200
但我想阻止远程访问只允许本地访问。
如何设置?
无需通过更改设置来禁用整个 HTTP 协议http.enabled
(/etc/elasticsearch/elasticsearch.yml
因为您的某些 API 可以使用我的情况下的 HTTP 端点),您可以network.host: localhost
在同一个文件中进行设置。
这将使您的:9200
HTTP 访问只能从您的本地机器/服务器获得。
You should set http.host to "127.0.0.1". This way you can access http on port 9200 from host itself, however not from outside. This also allows you to put a proxy which listens on some other port and filters and passes the requests selectively to elasticsearch node on localhost:9200.
For example, you may want to reject the request for shutdown, do a basic authentication using nginx and then pass all query requests to elasticsearch cluster url at http://localhost:9200.
This doesn't involve firewall.
Elasticsearch 允许您禁用 http 端点,只是在设置http.enabled
中设置为 false。它还允许拥有一个只能在同一个 jvm 中访问的本地节点。另一方面,您要问的是如何只允许本地访问其余端点,这是不同的,需要使用其他工具。
事实上,将 elasticsearch 暴露在互联网上并不是一个好主意。我会使用像 apache 或 Nginx 这样的代理来限制对它的访问,例如只打开一些可用的端点,但只有当您有外部用户想要直接向 elasticsearch 发送消息时才需要这样做。通常情况并非如此。或者,如果您只是想拒绝所有外部用户访问它,例如只有您的网站或应用程序需要访问它,只需使用防火墙并设置适当的规则来关闭 9200 端口。