Question

Setting up NGINX reverse proxy for DO function

I am trying to setup a reverse proxy for a DO function so I can use our standard domain on the function. I have setup a new droplet and setup NGINX to do this.

I have configured NGINX as such:

server_name api.mydomain.com;
location / {
proxy_pass https://mydofunctionurl/test;
include proxy_params;
}

I am having Cloudflare errors being returned. I assume Cloudflare is on the DO Function as I have not configured Cloudflare on the droplet.

Error:

## DNS resolution error
## What happened?
You've requested a page on a website (api.mydomain.com) that is on the [Cloudflare](https://www.cloudflare.com/5xx-error-landing/) network. Cloudflare is currently unable to resolve your requested domain (api.mydomain.com). There are two potential causes of this:

-   **Most likely:** if the owner just signed up for Cloudflare it can take a few minutes for the website's information to be distributed to our global network.
-   **Less likely:** something is wrong with this site's configuration. Usually this happens when accounts have been signed up with a partner organization (e.g., a hosting provider) and the provider's DNS fails.

Any ideas on how I can correct this configuration?


Submit an answer


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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I managed to get a working configuration for this. The droplet(s) running NGINX are set behind a load balancer that forwards onto port 80 on the private network. NGINX configured as so:

server {
  listen **private ip**:80;
  resolver 8.8.8.8  ipv6=off valid=10s;
  location / {
  rewrite /(.*) /$1 break;
  proxy_pass https://**functions url**/api/v1/web/**namespace**/default/$1;
  proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  proxy_ssl_server_name on;
}

Matt Welke
DigitalOcean Employee
DigitalOcean Employee badge
February 8, 2023

I am trying to setup a reverse proxy for a DO function so I can use our standard domain on the function.

I’m going to let someone else jump in to help you with your NGINX issue, but I just wanted to mention that if the only reason you want to do this is to use your custom domain with your function, you might be able to do this by deploying your function as a component in App Platform. Part of the integration of Functions within App Platform is that the domain you set up for App Platform is used with a proxy that proxies requests to the functions you deploy as components.

The page https://docs.digitalocean.com/products/app-platform/how-to/manage-functions/ in our docs about how to add functions to your App Platform app. The page https://docs.digitalocean.com/products/app-platform/how-to/manage-domains/#add-a-custom-domain in our docs talks about how to add a custom domain to your app.

You’ll notice that once you’ve got a custom domain added to your app, and you have functions deployed as part of your app (in either order), your function URLs will use your custom domain instead of the auto generated one owned by DigitalOcean.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up