我有兩個配置的服務器和運行OM我的Debian服務器。一臺主服務器和一臺Elasticsearch(搜索引擎)服務器。的Javascript得到HTTPS服務器爲localhost要求:自簽署端口SSL
主服務器在具有NGINX代理和購買的SSL證書的https節點服務器上運行。 Elasticsearch服務器正在http服務器上運行。我添加了一個新的NGINX代理服務器https://localhost:9999重定向到http://localhost:9200使用自簽名的SSL證書。 Elasticsearch服務器上還有一個使用用戶名和密碼的已配置身份驗證。
一切似乎是正確配置,因爲我可以從服務器獲取成功響應時,我做的從服務器端捲曲朝https://localhost:9999與-k選項繞過自簽名證書的verication沒有它,它不起作用。
我無法從我的https主服務器向我的http本地主機服務器執行跨域請求。因此我需要在我的本地主機服務器上配置https。
沒有-k選項:
curl: (60) SSL certificate problem: self signed certificate
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.
隨着-k選項:
{
"name" : "server-name",
"cluster_name" : "name",
"cluster_uuid" : "uuid",
"version" : {
"number" : "x.x.x",
"build_hash" : "abc123",
"build_date" : "Timestamp",
"build_snapshot" : false,
"lucene_version" : "x.x.x"
},
"tagline" : "You Know, for Search"
}
這是一個成功的Elasticsearch服務器響應。
所以完整的捲曲請求看起來像curl -k https://localhost:9999/ --user username:password
。
所以,實際的問題:
我希望能夠做到對這個服務器的簡單的jQuery AJAX請求。我正在嘗試以下要求$.get('https://username:[email protected]:9999/')
但我得到ERR_CONNECTION_REFUSED
。
我的猜測是,AJAX請求不會繞過自簽名證書驗證,因此它拒絕連接。
是否有請求頭之類的東西來解決這個問題沒有簡單的方法?或者我是否需要購買CA證書才能使用AJAX工作?
非常感謝您的回覆。我會試試這個並回復你。 –
這是否意味着我必須向我的節點後端發出請求並向es發送請求並將響應發送回前端?或者我可以用純粹的前端解決這個問題嗎?我不是100%確定這個例子中發生了什麼:)我可以用你的例子配置Elasticsearch併成功地ping通https服務器。 –
本示例告訴ElasticSearch使用自定義連接類來執行它的ajax請求。查看我上面的編輯 – Mawcel