Access cloudflare workers with Nginx proxy

Hey all,

I have setup a web server with nginx and want to access one of my workers through the proxy feature nginx supports. When i add the worker url in the proxy pass and try to access through nginx server domain it gives 403 forbidden and 421 Misdirect Error.

Any assitance or suggestions are appreciated.


Is nginx throwing an error or is the worker?

@Cyb3r-Jak3 Thank you for reply.

The nginx seems to be connecting with Worker, i also tested the proxy config with domain and it works but not with the worker domain.

The nginx config is:

server {
listen 80;

location /{
proxy_set_header Host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

I have used this example code on the worker:

Let me know, if @Cyb3r-Jak3 need more information regarding with config or the setup.

Here is a reference link, which i am testing this project on:


Right now its proxing through a test site, and if you http://test/cf-worker, it has configured to proxy

But instead gives 502 Bad Gateway.

It seems to load for me

I was testing it with some other domain, try now.

Ah yeah, I see the error now. What do the nginx error logs show?

The error logs seems to be clear, let me share you the server details for you to investigate:


the nginx config file: /etc/nginx/sites-available/proxy

Even if this link is single use, it’s very strongly discouraged to share credentials.

Please. refrain from doing so here, nor anywhere else.


I opened the link to break it for everyone else. I am not going to log in into a random server. I’ll try and recreate this locally to get it to work.

1 Like

Thanks Cyber and Mateo.

Can you try setting proxy_ssl_server_name on; in your location block? I know when I was doing nginx and R2 you need this, otherwise nginx makes a request to the IP address which Cloudflare blocks.

It Worked, Cyber, the proxy passed, thank you for the assitance.

That seems to be a nginx problem, not related to Cloudflare. You should check out Server Fault for those types of questions.

1 Like

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