
嘗試使用 IIS 管理器 10 和 httpPlatformHandler 1.2 在 Windows Server 2016 上託管帶有 PostgreSQL 資料庫的 Django 4 應用程式。
當使用 cmd 在 VM 伺服器上運行時,應用程式和資料庫可以正常運作python manage.py runserver
。嘗試使用 IIS 存取時出現問題,日誌檔案顯示:
psycopg.OperationalError: connection failed: :1), port 23825 failed: could not receive data from server: Socket is not connected (0x00002749/10057)
could not send SSL negotiation packet: Socket is not connected (0x00002749/10057)
在我從 localhost ot 127.0.0.1 更改資料庫位址後,錯誤更改為
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\psycopg\connection.py", line 729, in connect
raise ex.with_traceback(None)
django.db.utils.OperationalError: connection failed: could not receive data from server: Socket is not connected (0x00002749/10057)
could not send SSL negotiation packet: Socket is not connected (0x00002749/10057)
有時
psycopg.OperationalError: connection failed: could not receive data from server: Socket is not connected (0x00002749/10057)
could not send SSL negotiation packet: Socket is not connected (0x00002749/10057)
我認為 IIS 中有一些選項會阻止建立連線。
答案1
如果您還沒有這樣做,您可能需要更新「pg_hba.conf」文件,以允許透過 IPv4 和 IPv6 從本機進行連線。
#TYPE DATABASE USER ADDRESS METHOD
host all all 127.0.0.1/32 trust
host all all localhost trust
host all all ::1/128 trust
您可以在此處找到更多資訊。 https://www.postgresql.org/docs/current/auth-pg-hba-conf.html