rails postgres 适配器是否支持 ssl? [英] does rails postgres adapter support ssl?

查看:20
本文介绍了rails postgres 适配器是否支持 ssl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置一个 rails 应用程序以远程连接到 postgres 数据库.我注意到 mysql 的连接适配器具有指定设置 ssl 连接所需信息的选项,但 postgres/pg 适配器没有等效选项.

i'm trying to configure a rails app to remotely connect to a postgres db. i've noticed that the connection adapters for mysql have options that specify the required info for setting up an ssl connection, but there is no equivalent options for the postgres/pg adapter.

在谷歌搜索之后,我也找不到任何东西(只能通过 ssh 隧道连接).

after googling around, i haven't been able to find anything either (only connecting via an ssh tunnel).

很简单,是否试图让 rails postgres 适配器通过 ssl 连接到死胡同?

so simply, is trying to get the rails postgres adapter to connect over ssl a dead end?

谢谢.任何帮助或指导表示赞赏.

thanks. any help or direction is appreciated.

-h

推荐答案

在 2012 年末,事情似乎发生了变化.尽管文档仍然很少,但 pg gem 似乎可以自动协商 SSL,并且可以强制 jdbc 驱动程序使用 SSL.

In late 2012, things seem to have changed. Although documentation is still sparse, the pg gem seems to auto-negotiate SSL, and the jdbc drivers can be coerced to use SSL.

我的应用程序是一个混合 MRI-jRuby 应用程序,它访问需要 SSL 的云 postgresql 服务器 heroku-postgres.

My app is a hybrid MRI-jRuby app, that accesses heroku-postgres, a cloud postgresql server that requires SSL.

# Gemfile.lock
pg (0.14.1)

activerecord-jdbc-adapter (1.2.2.1)
activerecord-jdbcpostgresql-adapter (1.2.2.1)
jdbc-postgres (9.1.901)

pg gem,似乎可以自动协商 SSL.但是,JDBC 适配器没有.MRI连接了一个典型的database.yml(没有提到ssl),但是JDBC扔了:

The pg gem, seemed to auto-negotiate SSL. However, the JDBC adapter did not. MRI connected with a typical database.yml (no mention of ssl), but JDBC threw:

(FATAL: no pg_hba.conf entry for host "xx.xx.xx.xx", user "username", database "database", SSL off)

我最终尝试以 JDBC-URL 格式指定连接详细信息,并且连接成功:

I eventually tried specifying the connection details in JDBC-URL format, and the connection succeeded:

# jruby database.yml
production:
  adapter: jdbcpostgresql
  url: jdbc:postgresql://host/database?user=user&password=password&ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory

(可能并非所有设置都需要 sslfactory)

(sslfactory may not be needed for all setups)

这篇关于rails postgres 适配器是否支持 ssl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆