Django 错误提示“无法连接到服务器:权限被拒绝”

Django 错误提示“无法连接到服务器:权限被拒绝”

尝试访问我的 Django 应用时出现错误。我运行的是 Gentoo,Web 服务器是 Apache,带有 mod_wsgi 模块来显示 Django。错误信息如下

OperationalError at /admin/
could not connect to server: Permission denied
Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

我知道 Django 可以连接到 Postgres 数据库,因为我可以python manage.py syncdb成功运行。我也可以使用 进入交互式终端psql -U root -d mysite

ls -la插座的

root@ip-99-99-99-99 /var/run/postgresql # ls -la
total 12K
drwxr-x--- 2 postgres 4.0K Mar  7 18:39 ./
drwxr-xr-x 6 root     4.0K Mar  7 22:58 ../
srwxrwxrwx 1 postgres    0 Mar  7 23:31 .s.PGSQL.5432
-rw------- 1 postgres   71 Mar  7 23:31 .s.PGSQL.5432.lock

答案1

好奇……作为一个快速测试,尝试运行chmod o+rx /var/run/postgresql——如果这能解决问题(我怀疑它会),那么您需要诊断目录上的权限为何出错。在我的系统(Debian Squeeze)上,权限是 2775 postgres:postgres;虽然没有必要采用这种特定模式,但您需要(至少)o+x 允许其他用户遍历目录以到达套接字。

相关内容