Latest Posts

Set Up CloudFlare Workers to Use Your Own Domain

CloudFlare is the world’s leading provider of CDN solutions and domain name registration resolution solutions, and Workers is a serverless application based on its powerful CDN global cloud network.
Having previously shared a post about how to create a serverless reverse proxy using CloudFlare Workers, the long domain name (https://proxy1.51sec.workers.dev) created by this method is not suitable for sharing, so I was consider using my own domain name (https://proxy.51sec.org) to access it. Searched online, but about this piece of information is quite written unclear and difficult to start, so here to make a note for my own reference.



Principle

As long as the CloudFlare CDN itself supports a domain name that can be used as a CloudFlare Workers domain name, it is important to note that the domain name needs to be hosted or pointing on CloudFlare, i.e. the name service of the domain name must be CloudFlare.

Steps

The main two steps are to add a custom domain name to the CloudFlare network and the other to associate the domain name to the Worker sub-domain name. There are no strict requirements for the order of these two steps.

Custom domain names

As mentioned earlier, domain names, such as 51sec,org must be hosted on or pointing to CloudFlare, and other DNS registrars cannot access through CNAME, which will result in various weird errors.
Domain hosting or pointing to CloudFlare is easy, will use CloudFlare will, no longer repeat, according to the page prompt scant can be:




添加域名

After the domain name is successfully added, a new DNS record is added, Name is the subdomain to be customized (such as  proxy.51sec.org). The value does not matter, the key is to enable the Proxied.




添加记录

Associated domain names

After you create Workers switch to your domain's Workers tab for the domain name (note that the domain name is here, where in Workers you won't find a place to associate it with your domain and then add the association to Add route




添加路由

Route fills in the subdomain with /*, (proxy.51sec.org/*) ,Worker selects the worker application we created before, who needs to customize the domain name access, so you need to create a Worker and then associate , to represent access to the Worker service through this custom domain name: proxy.51sec.org/*




关联路由

When you’re done, you can access the  Worker service through a custom domain name, such as https://proxy.51sec.org/

Summarize

To summarize, two key points:
  • The domain name must be hosted on CloudFlare;
  • The worker needs to be added as a route association after it is created;

YouTube:

References

No comments