Setting Up a Universal Reverse Proxy with Cloudflare
Setting Up a Universal Reverse Proxy with Cloudflare
Registering a Domain
First, you need to register a domain. The registration process is not covered here, but I used a domain registered with Alibaba Cloud.
Adding DNS Records and Configuring DNS in Cloudflare
Click on the "Websites" option in the sidebar, then click the "Add Site" button.
Wait for Cloudflare to scan and add DNS records. You can add a subdomain record called "proxy," which will be dedicated to the reverse proxy.
Go to your domain registrar’s dashboard and choose the DNS service. Change the DNS addresses to Cloudflare's DNS addresses:
- armfazh.ns.cloudflare.com
- kelly.ns.cloudflare.com
Be patient while the DNS records propagate.
Now your domain has been successfully added to Cloudflare.
Configuring Workers
Next, we will use the open-source project cloudflare-reverse-proxy.
In the sidebar, click "Workers and Pages," then click on "Overview" and hit the "Create Application" button, followed by "Create Workers."
Enter a name, then click the "Deploy" button.
Click on the Worker you just created, then hit the "Quick Edit" button.
Copy and paste the code from the
_worker.js
file of the project into the editor.Click "Deploy" to set up the reverse proxy.
Configuring a Custom Domain
The address generated by Cloudflare is automatically created and not very elegant. If you want to configure your own domain, follow these steps:
Click on the "Triggers" tab, then hit the "Add Custom Domain" button.
Enter your custom domain that you’ve pointed to Cloudflare, and click "Add"