Greetings, I’m trying to connect my postgREST API that’s running from my droplet, to my main domain that’s on Digital Ocean’s app platform. I’m a little confused on how to do so because I cannot manually configure my main domain’s VM. I’m pretty new with networking like this but I believe I’m looking to set up a proxy?
Given from postgREST documentation, the nginx config file looks something like this. if my domain name from the App platform is called, DOMAIN.com, where would that be configured here? I only want my postgREST running on localhost in the VM, but can be accessed using my domains http address.
http {
...
# upstream configuration
upstream postgrest {
server localhost:3000;
keepalive 64;
}
...
server {
...
# expose to the outside world
location /api/ {
default_type application/json;
proxy_hide_header Content-Location;
add_header Content-Location /api/$upstream_http_content_location;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass http://postgrest/;
}
...
}
}
Would really appreciate some guidance here. thank you!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi there,
To connect your PostgREST API running on a Droplet to your main domain on the DigitalOcean App Platform, you’re on the right track with setting up a proxy! Utilizing nginx as a reverse proxy can forward requests to your PostgREST API.
Given the provided nginx configuration and your scenario, let’s walk through how you might configure this:
http {
...
upstream postgrest {
server localhost:3000;
keepalive 64;
}
server {
listen 80;
server_name api.DOMAIN.com; # Subdomain for the API
location /api/ {
default_type application/json;
proxy_hide_header Content-Location;
add_header Content-Location /api/$upstream_http_content_location;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass http://postgrest/;
}
}
...
}
Supposing you want to use DOMAIN.com for your frontend hosted on the DigitalOcean App Platform, you would configure a custom domain through the App Platform UI.
Ensure your domain’s DNS settings are configured correctly:
DOMAIN.com should point to your App on the DigitalOcean App Platform.api.DOMAIN.com should point to the droplet running your PostgREST API and nginx.A | DOMAIN.com | App Platform IP
CNAME | api.DOMAIN.com | Droplet IP address
Ensure to use HTTPS for your connections:
SSL for Droplet: You should also secure your API using SSL. You can use Certbot to easily add a free Let’s Encrypt certificate to your nginx setup.
SSL for App Platform: For your app running on the DigitalOcean App Platform, SSL certificates are automatically provided, so ensure to access your app using https://DOMAIN.com.
Your API runs on a droplet, and you use nginx to expose it, securing it with SSL. It will be accessible via https://api.DOMAIN.com.
Your main app on the DigitalOcean App Platform is accessible via https://DOMAIN.com.
The app on https://DOMAIN.com can communicate with your API over the internet securely by making requests to https://api.DOMAIN.com/api/.
Once configured, ensure to test by making a request to https://api.DOMAIN.com/api/ to confirm that nginx is correctly proxying requests to your PostgREST API.
This setup keeps your API on a subdomain and your main app on the primary domain, segregating the two while allowing for secure communication between them. Always remember to keep your software, and configuration, especially security-related, up-to-date.
Hope that this helps!
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.