Postgresql Postgrex-没有主机的pg_hba.conf条目;xxx.xxx.xxx.xxx“;

Postgresql Postgrex-没有主机的pg_hba.conf条目;xxx.xxx.xxx.xxx“;,postgresql,phoenix-framework,ecto,Postgresql,Phoenix Framework,Ecto,我有一个单独托管的Postgres数据库,我正试图与我的Phoenix应用程序一起使用。我的prod配置是: config :my_app, MyApp.Repo, adapter: Ecto.Adapters.Postgres, url: "postgres://username:password@myhost:5432/my_database", size: 20 当我的应用程序托管在Heroku上时,它工作得很好,但由于我已将其移动到VPS,我不断遇到以下错误: 17:07

我有一个单独托管的Postgres数据库,我正试图与我的Phoenix应用程序一起使用。我的
prod
配置是:

config :my_app, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  url: "postgres://username:password@myhost:5432/my_database",
  size: 20 
当我的应用程序托管在Heroku上时,它工作得很好,但由于我已将其移动到VPS,我不断遇到以下错误:

17:07:13.665 [info] GET /subjects
17:07:13.707 [info] Processing by MyApp.SubjectController.index/2
  Parameters: %{"format" => "html"}
  Pipelines: [:browser, :authorize]
17:07:13.951 [error] GenServer #PID<0.515.0> terminating
** (exit) %Postgrex.Error{message: nil, postgres: %{code: :invalid_authorization_specification, file: "auth.c", line: "474", message: "no pg_hba.conf entry for host \"xxx.xxx.xxx.xxx\", user \"username\", database \"my_database\", SSL off", pg_code: "28000", routine: "ClientAuthentication", severity: "FATAL"}}
17:07:13.970 [info] Sent 500 in 305ms
17:07:13.972 [error] #PID<0.513.0> running MyApp.Endpoint terminated
Server: xxx.xxx.xxx.xxx:80 (http)
Request: GET /subjects
** (exit) exited in: GenServer.call(#PID<0.515.0>, {:query, "SELECT s0.\"id\", s0.\"name\", s0.\"inserted_at\", s0.\"updated_at\" FROM \"subjects\" AS s0", []}, 5000)
    ** (EXIT) %Postgrex.Error{message: nil, postgres: %{code: :invalid_authorization_specification, file: "auth.c", line: "474", message: "no pg_hba.conf entry for host \"xxx.xxx.xxx.xxx\", user \"username\", database \"my_database\", SSL off", pg_code: "28000", routine: "ClientAuthentication", severity: "FATAL"}}

这太愚蠢了,但我解决了问题。我试图连接到的主机需要安全的数据库连接。默认情况下,SSL已关闭,因此我必须启用它:

config :my_app, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  url: "postgres://username:password@myhost:5432/my_database",
  ssl: true,
  size: 20 


感谢您的回答:

pg_hba.conf是一个列出您可以从何处连接到数据库的文件,因此它没有提到您尝试连接到的主机名也就不足为奇了。另外,您具体尝试了什么?也许这个问题需要包括您当前的pg_hba.conf.Updated。我添加了最后一行以允许访问所有人的所有地址。请删除此问题,因为这是一个简单的配置问题。为什么?这仍然可以帮助其他开发人员。:)
config :my_app, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  url: "postgres://username:password@myhost:5432/my_database",
  ssl: true,
  size: 20