透過 apache 進行 Postgres 驗證的問題

透過 apache 進行 Postgres 驗證的問題

我使用的是 RHEL 5.4,並且我已經設定了薑戈使用 PostgreSQL 作為資料庫的專案(我以前使用過 MySQL,但想嘗試一些新的東西:))。當我運行 Django 測試伺服器時,一切正常,我還可以透過密碼驗證透過命令列進行連線:

psql -U myuser -h 127.0.0.1

但是,當我嘗試透過 Apache 存取我的專案時,我收到 500 錯誤代碼,並在 apache 的錯誤日誌中收到此 python 回溯:

mod_wsgi (pid=7026): Exception occurred processing WSGI script '/var/www/myproject/myproject/hook.wsgi'.
Traceback (most recent call last):
  File "/var/www/myproject/myproject/src/django/django/core/handlers/wsgi.py", line 245, in __call__
    response = middleware_method(request, response)
  File "/var/www/myproject/myproject/src/django/django/contrib/sessions/middleware.py", line 36, in process_response
    request.session.save()
  File "/var/www/myproject/myproject/src/django/django/contrib/sessions/backends/db.py", line 55, in save
    obj = Session(
  File "/var/www/myproject/myproject/src/django/django/contrib/sessions/backends/base.py", line 152, in _get_session_key
    self._session_key = self._get_new_session_key()
  File "/var/www/myproject/myproject/src/django/django/contrib/sessions/backends/base.py", line 144, in _get_new_session_key
    if not self.exists(session_key):
  File "/var/www/myproject/myproject/src/django/django/contrib/sessions/backends/db.py", line 29, in exists
    Session.objects.get(session_key=session_key)
  File "/var/www/myproject/myproject/src/django/django/db/models/manager.py", line 132, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/var/www/myproject/myproject/src/django/django/db/models/query.py", line 336, in get
    num = len(clone)
  File "/var/www/myproject/myproject/src/django/django/db/models/query.py", line 81, in __len__
    self._result_cache = list(self.iterator())
  File "/var/www/myproject/myproject/src/django/django/db/models/query.py", line 269, in iterator
    for row in compiler.results_iter():
  File "/var/www/myproject/myproject/src/django/django/db/models/sql/compiler.py", line 672, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/var/www/myproject/myproject/src/django/django/db/models/sql/compiler.py", line 726, in execute_sql
    cursor = self.connection.cursor()
  File "/var/www/myproject/myproject/src/django/django/db/backends/__init__.py", line 75, in cursor
    cursor = self._cursor()
  File "/var/www/myproject/myproject/src/django/django/db/backends/postgresql_psycopg2/base.py", line 136, in _cursor
    self.connection = Database.connect(**conn_params)
OperationalError: could not connect to server: Permission denied
\tIs the server running on host "127.0.0.1" and accepting
\tTCP/IP connections on port 5432?

我查了conn_params字典,它包含正確的使用者名稱和密碼。我的pg_hba.conf看起來像這樣(我在 Ubuntu 9.04 伺服器上有完全相同的配置,一切正常):

local   all         postgres                          ident
local   all         all                               md5
host    all         all         127.0.0.1/32          md5
host    all         all         ::1/128               md5

我究竟做錯了什麼?

答案1

常見的錯誤之一是以純文字形式指定密碼,而根據您的情況pg_hba.conf配置應以 md5 形式提供。
使用 md5 更新設定檔中的密碼,然後重試。您可以使用任何 MD5 產生器,例如這個

相關內容