gpt4 book ai didi

django 无法连接到服务器 : Permission denied Is the server running on host and accepting TCP/IP connections on port remote host

转载 作者:行者123 更新时间:2023-11-29 11:37:49 24 4
gpt4 key购买 nike

我有一个奇怪的问题。我可以从命令行使用 psql 连接到远程主机,但不能在 django 设置文件中使用完全相同的凭据。我收到错误:

Could not connect to server: Permission denied Is the server running on host "remote ip" and accepting TCP/IP connections on port port_number?

如果我可以使用 psql 而不是使用 django 进行连接,我在这里缺少什么?我还通过 python 解释器检查了我可以加载 psycopg2。

非常感谢任何帮助,因为我在网上找到的内容都没有帮助。

干杯,

D

这是 settings.py 中的 db conf

'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': '<db name goes here>', # Or path to database file if using sqlite3.
'USER': '<db user>', # Not used with sqlite3.
'PASSWORD': '<pswd goes here>', # Not used with sqlite3.
'HOST': '<remote ip goes here>',
'PORT': '5432',
}

最佳答案

根据您的描述,这与 Apache 及其访问数据库的权限有关。你没有提到你使用的是哪个操作系统,但如果它正在运行 SELinux,则默认规则会阻止 apache 连接到 db。如果是这种情况,您可以通过运行暂时启用它:

setsebool httpd_can_network_connect_db

Here有更详细的说明。

关于django 无法连接到服务器 : Permission denied Is the server running on host and accepting TCP/IP connections on port remote host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8056444/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com