Cloudflare Tunnel with Postgres DB

jimmysafePRO

8 months ago

I have a cloudflared project which includes a Nextjs application and a Postgres DB.

The nextjs application talks privately with the Postgres db through private networking.

The tunnel is setup correctly for the nextjs application over http and it works fine.

What i would like to achieve is to be able to connect to the postgres db from my local machine (whitelisting my ip address) without publicly exposing the db to the internet.

So i tried to assign a **Cloudflare Tunnel Public Hostname **to Postgres (db.mydomain.com) and then make it accessible by certain IPs with Cloudflare ACLs.

I am definitely doing something wrong here:

I have created a public hostname with tcp protocol and passed in the railway private networking url (see image).

but unfortunately when i try to connect to the db from my local machine, the connection times out.

PS: i have not setup any ACLs yet so i am just trying to successfully connect to the db first.

I really hope someone can give me a hand on this one.

Thanks in advance

0 Replies

jimmysafePRO

8 months ago

N/A


redstars071TRIAL

8 months ago

I don't think it's a good idea to do something like that for the database


redstars071TRIAL

8 months ago

In this way you are hosting it to the public the database


redstars071TRIAL

8 months ago

Try using the env DATABASE_PRIVATE_URL and link it to the site, without making the database public


redstars071TRIAL

8 months ago

Because for example in my postgres case, I use the private networking connection to connect the database to my bot


dane-stevensPRO

8 months ago

You need to leave out the railway.internal in the URL. Should be just postgres:5432

I would recommend installing cloudflare warp on your local machine, and putting [db.basilico.studio](db.basilico.studio) behind cloudflare access.


jimmysafePRO

8 months ago

@Dane thanks for the hint, unfortunately just using postgres:5432 in the public hostname configuration does not work.
Also i don't see how Cloudflare WARP can help me out on this.

All i need is just to access the db hosted on Railway without exposing it to the public, it seems i can't find a solution to this 😭


8 months ago

is this a usecase for a cloudflare tunnel? I feel like this is what tailscale is for


jimmysafePRO

8 months ago

@Brody thanks very much i didnt know about tailscale! That is exactly what i need.

Do you think cloudflare tunnels and tailscale play well together?


8 months ago

I don't think they really have anything to do with one another tbh


8 months ago

@jimmy - I wrote a guide on how to set-up tailscale -


Cloudflare Tunnel with Postgres DB - Railway Help Station