我已经在我的EC2 ubuntu(18)上安装了Postgres 10.但我不能从我的本地Mac访问它.得到这个错误.
我的设置是:
我更新了Postgres配置:
- 在/etc/postgreSQL/10/main/pg_hba.conf中添加了以下行:
host all all 0.0.0.0/0 md5
host all all ::/0 md5
- 在/etc/postgreSQL/10/main/postgresql.conf中更改了此行:
listen_addresses = '*' # what IP address(es) to listen on;
- 我确实将密码设置为默认的‘postgres’用户,我正在使用它从外部连接到数据库;
在EC2实例上,我更改了:
在EC2实例上,此命令返回端口已公开:
ubuntu@ip-XXXXXXXXXX:~$ netstat -nat |grep :5432
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN
tcp6 0 0 :::5432 :::* LISTEN
看起来EC2实例实际上没有公开此端口.其他端口(如:80或:22)可以正常访问,但端口:5432返回错误:
➜ ~ nc -zv XX.XXX.XXX.XXX 80
Connection to XX.XXX.XXX.XXX port 80 [tcp/http] succeeded!
➜ ~ nc -zv XX.XXX.XXX.XXX 5432
nc: connectx to XX.XXX.XXX.XXX port 5432 (tcp) failed: Operation timed out
我的EC2实例上也安装了Nginx,它的配置是:
server {
charset utf-8;
listen 80;
server_name XXXXXXXXXXXXXXX.ca; # <--- hidden domain name
location / {
root /opt/frontend/develop/dist/tweeter-ui/;
try_files $uri /index.html;
}
location /api/ {
proxy_pass http://localhost:8080/api/;
}
}
PostgreSQL服务正在运行:
ubuntu@ip-XXXXXXXXXX:~$ service postgresql status
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Wed 2022-11-23 22:41:33 UTC; 1h 6min ago
Process: 6283 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 6283 (code=exited, status=0/SUCCESS)
Nov 23 22:41:33 ip-XXXXXXXXXX systemd[1]: Starting PostgreSQL RDBMS...
Nov 23 22:41:33 ip-XXXXXXXXXX systemd[1]: Started PostgreSQL RDBMS.
我的设置出了什么问题?我在这个论坛和互联网上try 了很多不同的帖子,都没有用.(( 我是否还需要使用Postgres路由来配置Nginx?