Как добавить поддомен в cloudflare

export CF_API_EMAIL=you@example.com
export CF_API_KEY=abc123def456ghi789

Дальше через for хочу добавить домены из файла

for domain in $(cat domains.txt); do \
curl -X POST -H "X-Auth-Key: $CF_API_KEY" -H "X-Auth-Email: $CF_API_EMAIL" \
-H "Content-Type: application/json" \
"https://api.cloudflare.com/client/v4/zones" \
--data '{"name":"'$domain'","jump_start":true}'; done 

задан 4 июл 2018 в 9:19

Tick-Tack's user avatar

curl -s -X POST "https://api.cloudflare.com/client/v4/zones/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/dns_records" \
-H "X-Auth-Email: mail@example.com" \
-H "X-Auth-Key: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" \
-H "Content-Type: application/json" \
--data '{"type":"CNAME","name":"'$1'","content":"domain.com"}' > /dev/null

ответ дан 4 июл 2018 в 13:26

KAGG Design's user avatar

KAGG Design

4 золотых знака52 бронзовых знака

I have created id.example.com for country’s specific customer. I’ve done it by created cname id with alias example.com

I need to create customer portal: my.id.example.com. How?

Stephen Ostermiller's user avatar

asked Jun 12, 2015 at 12:01

  • In Cloudflare, open the DNS records for domain.example
  • Create a A record for example.id and enter the IP where my.id.domain.example will be hosted, and add record Как добавить поддомен в cloudflare
  • Setup the site my.id.domain.example at the IP you specified

Includes all benefits mentioned above for Dedicated Certificates
Protects your domain, subdomains (*.example.com), as well as up to 50
additional hostnames Can extend protection beyond first-level
subdomains (*.www.example.com, not just *.example.com) Dedicated SSL
certificates typically provision within a few minutes but can take up
to 24 hours.

Full details here

Stephen Ostermiller's user avatar

answered Jul 11, 2015 at 23:32

David Taiaroa's user avatar

David Taiaroa

7 gold badges62 silver badges50 bronze badges

answered Jun 12, 2015 at 19:20

damoncloudflare's user avatar

Simply create your record as you would any other record, and use my.id as the name (note the dot.) Lookup will work as you would expect it.

answered Jul 8, 2015 at 19:11

Читайте также:  Что такое ошибка 504 на сайте

Mihai Limbășan's user avatar

Mihai Limbășan

4 gold badges48 silver badges59 bronze badges

You’re probably an SEO-conscious person who wants the best of both worlds. That is to use two different websites/CMSs/applications on the same domain without using a subdomain.

But, wait! Google says using a subdomain doesn’t impact SEO!?

That is true, but anything that Google says has to be analyzed.

Watch this tutorial in my video or read ahead below.

But here’s where this unravels. 

If we are considering creating a brand new subdomain on a domain that has built up credibility and traffic over time, they will not be treated equally. The root domain has established its dominance, but the subdomain has not. I’m not sure if the subdomain is treated as a fresh domain or if you’re given some sort of boost because it’s piggybacking off the root domain. I do know that it won’t perform as well as the primary domain. Here are 14 case studies demonstrating subdomains getting moved to subdirectories and their traffic significantly increasing.

Using Cloudflare to Serve a Subdomain as a Subdirectory

Next, go to Workers and create one.

Cloudflare add worker

Note: I’ve updated the code in this snippet and the images are showing the older version. They’ll both work, but this version allows for more customization and it rejects post requests which this proxy can’t handle.

addEventListener('fetch', function(event) {
  event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
  // Only GET requests work with this proxy.
  if (request.method !== 'GET') return MethodNotAllowed(request);

  const url = new URL(request.url);
  const originUrl = url.toString().replace(
    'https://example.com',
    'https://blog.example.com'
  );
  const originPage = await fetch(originUrl);
  const newResponse = new Response(originPage.body, originPage);

  return newResponse;
}
function MethodNotAllowed(request) {
  return new Response(`Method ${request.method} not allowed.`, {
    status: 405,
    headers: {
      'Allow': 'GET'
    }
  })
}

Here’s what it looks like in the dashboard:

Читайте также:  Удалить учетную запись электронной почты в Thunderbird и Как удалить учетную запись электронной почты в Thunderbird Mail?

Add code to Cloudflare worker subdomain to subdirectory

Be sure to change out the URLs to yours. The first is your root domain, and the second is the subdomain/other website. In summary, the code looks at the URL being requested and swaps it out with another URL (while still making it appear to come from the URL requested).

Cloudflare add route for subdomain to subfolder

Add one more route. This route will be for the assets such as images, CSS, and JavaScript. While your blog is available at /blog, your assets are not. Find your asset URL. I recommend watching the video in the intro to help out with this. Once you have the asset URL add this as a route and save it.

After about 1 minute, you should be able to visit your website subdirectory and see your subdomain. Pretty cool!

Downsides of Proxying Your Subdomain Like This

You can only retrieve data from the server (GET requests); you cannot send data (POST requests). That means you can’t log in or submit forms.

You can submit forms if you use an embed of a form (e.g., Mailchimp signup) as those requests are made against their servers.

Update: I needed to submit forms on this setup and I did so by modifying the form action to be an absolute URL.

I hope this has worked for you and that you achieve a huge SEO boost! Feel free to reach out and hire me if you need assistance.

Оцените статью
Хостинги