NGINX reverse proxy to Cloudflare Pages returns 403 Forbidden

I am encountering an issue where I receive a “403 Forbidden” error when trying to access my Cloudflare Pages application through a Fly.io reverse proxy.

The reason I need a proxy is because our main site are hosted on Fly but the Documentation site (Docusaurus) is hosted on Cloudflare Pages and we want to serve the Documentation site under the root domain as https://company.com/docs

The following is the example of the proxy conf

location /docs {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Host $http_host;
    set $backend "https://documentation-demo.pages.dev";
    proxy_pass $backend;
   proxy_ssl_server_name on;
}

Could anyone advice if there is missing header specifically for Cloudflare Pages hosted site?

Note that I was able to proxy to a Discourse forum with additional 2 headers as following:

# A cdck-trust-proxy header with a specific value must be sent with every request
proxy_set_header cdck-trust-proxy xxxxxx;
# Proxy pass to Discourse upstream server. Use variable for resolver to honor DNS changes for upstream proxies
set $backend "https://xxxx-origin-by-discourse.com";

Thanks in advance,
Angeline

In case someone saw this thread, here is the working conf

server {
  listen 8080;
  proxy_ssl_server_name on;
  proxy_ssl_name $proxy_host;

  location /doc/ {
    proxy_set_header Host "xxx.pages.dev";
    proxy_set_header X-Real-IP $remote_addr;
    proxy_pass https://xxx.pages.dev/;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.