ElasticSearch即使禁用已禁用,也不允许使用CORS

时间:2019-07-10 09:17:16

标签: node.js reactjs elasticsearch

我正在kubernetes上运行ElasticSearch 6.6.1和一些NodeJS容器。通过NodeJS上传到elasticsearch没问题,但是我无法查询。

我的elasticsearch.yml


node.data: ${NODE_DATA:true}
node.master: ${NODE_MASTER:true}
node.ingest: ${NODE_INGEST:true}
node.name: ${HOSTNAME}

network.host: 0.0.0.0
# see https://github.com/kubernetes/kubernetes/issues/3595
bootstrap.memory_lock: ${BOOTSTRAP_MEMORY_LOCK:false}

discovery:
  zen:
    ping.unicast.hosts: ${DISCOVERY_SERVICE:}
    minimum_master_nodes: ${MINIMUM_MASTER_NODES:2}

# see https://github.com/elastic/elasticsearch-definitive-guide/pull/679
processors: ${PROCESSORS:}

# avoid split-brain w/ a minimum consensus of two masters plus a data node
gateway.expected_master_nodes: ${EXPECTED_MASTER_NODES:2}
gateway.expected_data_nodes: ${EXPECTED_DATA_NODES:1}
gateway.recover_after_time: ${RECOVER_AFTER_TIME:5m}
gateway.recover_after_master_nodes: ${RECOVER_AFTER_MASTER_NODES:2}
gateway.recover_after_data_nodes: ${RECOVER_AFTER_DATA_NODES:1}
http.cors.enabled : true
http.cors.allow-origin: "*"
http.cors.allow-methods: OPTIONS, HEAD, GET, POST, PUT, DELETE
http.cors.allow-headers: X-Requested-With, X-Auth-Token, Content-Type, Content-Length, Authorization, Access-Control-Allow-Headers, Accept

而且似乎可以正确读取elasticsearch.yml,因为卷曲地址可以得到

HTTP/1.1 200 OK
access-control-allow-origin: *
content-type: application/json; charset=UTF-8
content-length: 518

{
  "name" : "elasticsearch-client-65459787c-mkjws",
...

这是我的ReactiveBase组件:

    app="amalfi/default2"
    url="http://elasticsearch-client:9200"
    headers={{
         'Content-Type': 'application/json',
    }}
>

elasticsearch服务称为elasticsearch-client

当尝试通过http访问(网站使用https)时,我得到This request has been blocked; the content must be served over HTTPS. 但是当使用HTTPS时,我得到"Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at mysite.com",但是由于http.cors.allow-origin: "*",它应该允许来自任何地方的连接,对吗?

奇怪的是,我不得不上传到ElasticSearch时遇到问题,但是查询它有点棘手...

我尝试将确切地址设置为http.cors.allow-origin: https://my-address-here.com,但它给出了错误信息... 我也尝试过https.cors.allow-origin: /https?:\/\/localhost(:[0-9]+)?/,但结果相同。

0 个答案:

没有答案