Utilizing Nginx as a reverse proxy for Notion API in production results in Cloudflare 403/421 errors. Below is an alternative proxy setup:
location /notion/records {
proxy_ssl_server_name on;
proxy_ssl_name $upstream_server;
rewrite ^/notion/records(.*)$ /v1/collections/DB_UNIQUE_ID$1? break;
proxy_pass https://api.notion.com;
proxy_set_header Authorization "Bearer SECRET_TOKEN";
proxy_set_header Notion-Version "2022-06-28";
proxy_set_header Content-Type "application/json";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
How can this issue be resolved?
hey, try refining your header settings. my experince showed that cloudflare errors often vanish when u set the host and ssl_name correctly & update ip whitelist settings. sometimes a minor typos culd trigger those 403s.
After encountering similar issues, I found that the key was examining both the headers and the rewrite rules very carefully. Minor discrepancies in the configuration often trigger Cloudflare’s security measures. In my case, adjusting the host header explicitly to reflect the upstream API domain made a significant difference. I also verified that the SSL and forwarding settings conformed to Cloudflare’s recommendations and ensured that there were no conflicting rules in the Cloudflare dashboard. Reviewing each directive and testing configurations incrementally typically resolved the 403/421 errors.