![](/img/trans.png)
[英]django.db.utils.OperationalError: could not connect to server: Connection refused
[英]postgresql - django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "host_name" (XX.XX.XX.XX)
and accepting TCP/IP connections on port 5432?
嘗試設置數據庫服務器時出現典型錯誤消息。 但我只是無法解決。
我的Django數據庫設置:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'db_name',
'USER': 'db_user',
'PASSWORD': 'db_pwd',
'HOST': 'host_name',
'PORT': '5432',
}
}
我添加到pg_hba.conf
host all all 0.0.0.0/0 md5
host all all ::/0 md5
我替換為postgresql.conf
:
listen_addresses = 'localhost'
到listen_addresses = '*'
並沒有重啟PostgreSQL:
/etc/init.d/postgresql stop
/etc/init.d/postgresql start
但仍然出現相同的錯誤。 有趣的是:
我可以從外面ping XX.XX.XX.XX
,它可以正常工作。 但我無法遠程登錄:
telnet XX.XX.XX.XX
Trying XX.XX.XX.XX...
telnet: connect to address XX.XX.XX.XX: Connection refused
telnet: Unable to connect to remote host
如果我從外部遠程登錄端口22,則可以正常工作:
telnet XX.XX.XX.XX 22
Trying XX.XX.XX.XX...
Connected to server_name.
Escape character is '^]'.
SSH-2.0-OpenSSH_6.7p1 Debian-5+deb8u3
如果我從數據庫服務器內部遠程登錄端口5432,則會得到以下信息:
telnet XX.XX.XX.XX 5432
Trying XX.XX.XX.XX...
Connected to XX.XX.XX.XX.
Escape character is '^]'.
來自外部的相同端口:
telnet XX.XX.XX.XX 5432
Trying XX.XX.XX.XX...
telnet: connect to address XX.XX.XX.XX: Connection refused
telnet: Unable to connect to remote host
來自內部的nmap:
Host is up (0.000020s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
5432/tcp open postgresql
來自外部的nmap:
Starting Nmap 7.60 ( https://nmap.org ) at 2018-01-24 07:01 CET
也沒有回應。
聽起來像防火牆問題,但我不知道在哪里尋找。 我在做什么錯,這可能是問題所在?
任何幫助表示贊賞。
順便說一句:我可以登錄到服務器內部的postgresql,它的工作原理是:
psql -h host_name -U user_name -d db_name
psql (9.4.15)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.
db_name =>
我猜到問題是防火牆阻止了這些端口。 我嘗試與托管公司進行通信,但最后我不得不將服務器更改為其他托管公司,並且服務器使用了正確的設置
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.