1、将ES的账号:密码通过Base64加密
假设账号密码如下:
- 账号:elastic
- 密码:elastic@huayunworld.com
echo -n 'elastic:elastic@huayunworld.com' | base64
ZWxhc3RpYzplbGFzdGljQGh1YXl1bndvcmxkLmNvbQ==
2、在 Nginx 配置中传递认证信息
location /es/ {
proxy_pass http://es.huayunworld.com:9200/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Authorization "Basic ZWxhc3RpYzplbGFzdGljQGh1YXl1bndvcmxkLmNvbQ=="; # 认证信息,如何需要认证把此项注释掉.
proxy_redirect off;
}
3、测试
curl http://127.0.0.1/es/
{
"name" : "es1",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "FgishdSnQF2iPmanRsmfEw",
"version" : {
"number" : "7.17.6",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "f65e9d338dc1d07b642e14a27f338990148ee5b6",
"build_date" : "2022-08-23T11:08:48.893373482Z",
"build_snapshot" : false,
"lucene_version" : "8.11.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}