我正在使用 PHP elasticsearch 客户端。
如何通过阻止浏览器访问来保护生产服务器上的数据?
http://api .******************.co.uk:9200
最佳答案
编辑:聊天后,您的问题原来是您不想将 ES 暴露给外界,只暴露给您的应用程序。解决方案是通过设置将 ES 绑定(bind)到本地接口(interface):
network.host: 127.0.0.1
上一个答案:
通常,您将运行执行基本身份验证的 nginx(或其他网络服务器),然后将请求代理到 Elasticsearch。
这是一个精简的配置,可能会对您有所帮助。考虑为您的服务器使用 SSL/TLS,否则 BasicAuth 密码会以明文形式发送。
server {
listen 80 default_server;
server_name your.server.address.com;
client_max_body_size 50M;
location / {
# Pass requests to ElasticSearch
proxy_pass http://localhost:9200;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
# For CORS Ajax
proxy_pass_header Access-Control-Allow-Origin;
proxy_pass_header Access-Control-Allow-Methods;
proxy_hide_header Access-Control-Allow-Headers;
add_header Access-Control-Allow-Headers 'X-Requested-With, Content-Type';
add_header Access-Control-Allow-Credentials true;
# Authorize access
auth_basic "ElasticSearch";
auth_basic_user_file /etc/elasticsearch/passwords;
}
}
关于security - 通过浏览器保护 Elasticsearch 访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28953719/