AWS Lightsail - custom domain not working for Database

0

Hi!

I have an ubuntu lightsail server that is running a node express app and a postgres server. These were not from a template, I set these up myself, and the database is running in a docker container on the lightsail instance (this issue exists on non-docker postgres as well). I have a static IP set up. For networking, I have all TCP ports open to all IPv4 addresses.

Everything is set up and I'm able to visit my webapp at: <myipaddress>:8080 and my database at: <myipaddress>:5432

^that is working great.

I'm trying to get these to work with a subdomain on my site on namecheap. I added an A record with the corresponding subdomain, and the ip address.

After that^, my express app becomes reachable at subdomain.mydomain.com:8080, but my database is not reachable via the subdomain. This single A record was enough to get this to work on an identical setup in Vultr for both my express app and my database.

When I try to connect via the subdomain I get the following error from my postgres client: getaddrinfo ENOTFOUND subdomain.mydomain.com

After trying the A record, I applied all the NS (Name Server) records available on Domains & DNS tab. This didn't seem to have any effect on anything, from what I could tell. I have my subdomain assigned to my static ip in the assignments sub-tab.

I doubt it's a configuration issue with postgres, because it's working via the IP address directly. Would greatly appreciate any ideas.

Thanks so much!

  • Joe

Update:

I installed psql client, and I am able to open a connection to the database via the subdomain, not just the IP address.

Still unable to connect to the subdomain from my computer directly.

So I'm guessing it has something to do with some firewall configuration that I cannot see?

Update 2: I installed postgres directly onto the box and tore down my docker containers. I set up the config to allow external connections.

I am still able to connect to this postgres server via IP but NOT via my custom domain. So this issue is not specifically related to docker.

Edit: here is my compose.yaml, same setup as my vultr vps:

version: '3'
volumes:
  pgdata:
    driver: local
services:
  postgres:
    image: postgres
    environment:
      POSTGRES_PASSWORD: some_password_here
    ports:
      - '5432:5432'
    volumes:
      - pgdata:/var/lib/postgresql/base
    deploy:
      resources:
        limits:
          memory: 200M
1 Answer
0

Hello.

Still unable to connect to the subdomain from my computer directly.

Does this mean you can't access Lightsail's PostgreSQL from your home network?
Is it possible to perform subdomain name resolution from your home network?
If this doesn't work, there may be a problem with the DNS server your home network is referring to.

dig subdomain.com

Also, is it possible to perform domain name resolution from a Node.js application using the code below?
https://nodejs.org/api/dns.html#dns_dns

const dns = require("dns");
const dnsPromises = dns.promises;

dnsPromises.lookup("google.com").then(({ address, family }) => {
  console.log("address: %j family: IPv%s", address, family);
});
profile picture
EXPERT
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions