Set Up CloudFlare Workers to Use Your Own Domain - NETSEC

Latest

Learning, Sharing, Creating

Cybersecurity Memo

Saturday, March 21, 2020

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.itprosec.com) 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.


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.

Configuration 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 three steps.

1 Create a  sub-domain name 

As mentioned earlier, domain names, such as 51sec,org must be hosted on or pointing to CloudFlare, and other DNS registrars will result in various weird errors.
Domain hosting or pointing to CloudFlare is easy, create a dns A record and point to any valid ip address.


After a new DNS record is added, this A record name will be used for our Workers App's sub-domain. When adding this A record, name is the subdomain to be customized (such as  proxy.itprosec.com). The value of IPv4 address does not matter, but the key is to enable the Proxied.


2 Associated domain names to Workers

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



3 Create a Workers Route


Route fills in the subdomain with /*, (proxy.itprosec.com/*) ,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.itprosec.com/*


关联路由

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

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:

3 comments:

  1. hello, I've seen many tutorials teaching how to use your custom subdomain to reroute to your worker, but I want to use my main domain instead of a subdomain and I can't get it to work.

    ReplyDelete
    Replies
    1. I have not tested it, but I believe the process is same.
      Create a dns record for your main domain, then create a route for it.

      Delete
  2. hello, I've seen many tutorials teaching how to use your custom subdomain to reroute to your worker, but I want to use my main domain instead of a subdomain and I can't get it to work.

    ReplyDelete