簡體   English   中英

從 Rails 到 Mongodb 的連接通過 ssl 不起作用

[英]From Rails to Mongodb connection over ssl not working

I am able to connect mongodb from mongo shell over ssl(working): mongo --ssl --sslCAFile ca.crt --sslPEMKeyFile client.pem mongodb://xxxx:xxxx@xxxxx:27017/test_db?authSource=admin

從 rails 我無法連接我的 mongoid 配置文件如下:

development:
  clients:
    default:
      #database: mastt_development
      uri: mongodb://xxxx:xxxx@xxxxx:27017/test_db?authSource=admin
#      hosts:
#        - localhost:27017
  options:
    max_pool_size: 3
    wait_queue_timeout: 300
    ssl: true
    ssl_cert: /home/ubuntu/client.pem
    ssl_verify: true
    ssl_ca_cert: /home/ubuntu/ca.crt
 options:
    raise_not_found_error: false

rails c
2.6.2 :001 > User.count
Traceback (most recent call last):
        1: from (irb):1
Mongo::Error::NoServerAvailable (No primary server is available in cluster: #<Cluster topology=Unknown[prod-mongo-v2:27017] servers=[#<Server address=prod-mongo-v2:27017 UNKNOWN>]> with timeout=30, LT=0.015)
2.6.2 :002 > exit

MongDB服務器日志:

2020-06-12T06:22:05.955+0000 I  NETWORK  [conn680] end connection xx.xx.xx.xx:55240 (0 connections now open)
2020-06-12T06:22:16.549+0000 I  NETWORK  [listener] connection accepted from xx.xx.xx.xx:55241 #681 (1 connection now open)
2020-06-12T06:22:16.559+0000 I  NETWORK  [conn681] Error receiving request from client: SSLHandshakeFailed: The server is configured to only allow SSL connections. Ending connection from 157.45.197.173:55241 (connection id: 681)

請幫助解決此問題

您將這些選項設置為 Mongoid 選項,但需要將它們設置為驅動程序選項。 有關示例,請參見此處

簡而言之,將第一個options移動到與配置中的uri相同的級別。

您似乎在頂層也有兩次options

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM