{"id":2970,"date":"2023-11-09T20:02:20","date_gmt":"2023-11-09T13:02:20","guid":{"rendered":"https:\/\/dev.artru.net\/?p=2970"},"modified":"2024-10-05T11:45:56","modified_gmt":"2024-10-05T04:45:56","slug":"cung-cap-noi-dung-tinh-thong-qua-subdomain","status":"publish","type":"post","link":"https:\/\/artru.net\/en\/cung-cap-noi-dung-tinh-thong-qua-subdomain\/","title":{"rendered":"Provide static content through Subdomain"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Continue the website optimization program. In my previous article, I have instructions on how to do it <a href=\"\/en\/subdomain-va-cloudflare-lam-cdn-anh-mien-phi\/\" target=\"_blank\" rel=\"noreferrer noopener\">Combine Subdomain and Cloudflare as a free image CDN<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With this new method, it will be simpler. Providing static content through Subdomain does not require using additional hosting to store images.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create Subdomain<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">How to create a Subdomain is also quite simple, you just need to pay attention to the step of pointing the subdomain <strong>same directory<\/strong> with the main website.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example of creating a subdomain in cPanel.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Log in to cPanel and navigate to the section <strong>Domains<\/strong> \u2192 choose <strong>Create A New Domain<\/strong>.<\/li>\n\n\n\n<li>Enter the subdomain. For example <code data-no-translation=\"\" data-no-auto-translation=\"\">cdn.example.com<\/code>.<\/li>\n\n\n\n<li>Check the box <code data-no-translation=\"\" data-no-auto-translation=\"\">Share document root (\/home\/username\/public_html) with \"example.com\"<\/code> so that the subdomain can use the source of the main domain.<\/li>\n\n\n\n<li>Press the button <strong>Submit<\/strong>.<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"645\" height=\"506\" src=\"https:\/\/cdn.artru.eu.org\/wp-content\/uploads\/2023\/11\/Tao-subdomain-trong-cPanel.png\" alt=\"Create subdomain in cPanel\" class=\"wp-image-2983\"\/><figcaption class=\"wp-element-caption\">Create subdomain in cPanel<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"has-vivid-red-color has-black-background-color has-text-color has-background has-link-color wp-elements-045735367badd14594b3ce4df309970a wp-block-paragraph\"><strong>NOTE:<\/strong> It is required to point the subdomain to the root directory of the main domain. Each management panel will have a different setup. Example of Domain Pointers Alias in DirecAdmin. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Add CORS header<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Most popular browsers will ask you to set it up <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/CORS\" target=\"_blank\" rel=\"noreferrer noopener\">CORS header<\/a> for your domain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can set CORS to file <code data-no-translation=\"\" data-no-auto-translation=\"\">.htaccess<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\" data-no-translation=\"\" data-no-auto-translation=\"\"><code data-no-translation=\"\" data-no-auto-translation=\"\">&lt;IfModule mod_headers.c&gt;\n    Header set Access-Control-Allow-Origin \"*\"\n&lt;\/IfModule&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Replace URLs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This step simply rewrites the main domain name into a subdomain before serving it to users, so it will not affect the database. When you turn off the Plugin, the URL will return to the same.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">There are many plugins that support this such as CDN Enabler, Litespeed Cache, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you use the CDN Enabler plugin you must press a button <code data-no-translation=\"\" data-no-auto-translation=\"\">Save Changes<\/code> instead of <code data-no-translation=\"\" data-no-auto-translation=\"\"><s>Save Changes and Validate Configuration<\/s><\/code> then it saves the CDN configuration.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"698\" height=\"850\" src=\"https:\/\/cdn.artru.eu.org\/wp-content\/uploads\/2023\/11\/CDN-Enabler-Settings.png\" alt=\"CDN Enabler Settings\" class=\"wp-image-2992\"\/><figcaption class=\"wp-element-caption\">CDN Enabler Settings<\/figcaption><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">The setup in Litespeed Cache is similar to CDN Enabler but it has deeper options. You can configure different subdomains to serve different content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code data-no-translation=\"\" data-no-auto-translation=\"\">images.example.com<\/code> give the image.<\/li>\n\n\n\n<li><code data-no-translation=\"\" data-no-auto-translation=\"\">statics.example.com<\/code> for css, js files,\u2026<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"775\" src=\"https:\/\/cdn.artru.eu.org\/wp-content\/uploads\/2023\/11\/CDN-Mapping-Litespeed-Cache.png\" alt=\"CDN Mapping Litespeed Cache\" class=\"wp-image-3000\"\/><figcaption class=\"wp-element-caption\">CDN Mapping Litespeed Cache<\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">Connect Subdomain with Cloudflare<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To optimize your subdomain, you need to connect to Cloudflare to take advantage of the speed of Cache CDN. You just need to enable proxy <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-amber-color\">(Yellow Cloud)<\/mark> Just for subdomains. So this will not affect the main domain if you do not need to use it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I wrote about the steps to connect and set up subdomains in Cloudflare in a previous tutorial <a href=\"\/en\/subdomain-va-cloudflare-lam-cdn-anh-mien-phi\/#tao-subdomain\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Ti\u1ebfp t\u1ee5c ch\u01b0\u01a1ng tr\u00ecnh t\u1ed1i \u01b0u website. B\u00e0i vi\u1ebft tr\u01b0\u1edbc t\u00f4i c\u00f3 h\u01b0\u1edbng d\u1eabn c\u00e1ch K\u1ebft h\u1ee3p Subdomain v\u00e0 Cloudflare l\u00e0m CDN \u1ea3nh mi\u1ec5n ph\u00ed. V\u1edbi c\u00e1ch l\u00e0m m\u1edbi n\u00e0y s\u1ebd \u0111\u01a1n gi\u1ea3n h\u01a1n. Cung c\u1ea5p n\u1ed9i dung t\u0129nh th\u00f4ng qua Subdomain kh\u00f4ng c\u1ea7n s\u1eed d\u1ee5ng th\u00eam hosting ph\u1ee5 \u0111\u1ec3 l\u01b0u tr\u1eef h\u00ecnh \u1ea3nh. T\u1ea1o [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-2970","post","type-post","status-publish","format-standard","hentry","category-website"],"_links":{"self":[{"href":"https:\/\/artru.net\/en\/wp-json\/wp\/v2\/posts\/2970","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/artru.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artru.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artru.net\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artru.net\/en\/wp-json\/wp\/v2\/comments?post=2970"}],"version-history":[{"count":0,"href":"https:\/\/artru.net\/en\/wp-json\/wp\/v2\/posts\/2970\/revisions"}],"wp:attachment":[{"href":"https:\/\/artru.net\/en\/wp-json\/wp\/v2\/media?parent=2970"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artru.net\/en\/wp-json\/wp\/v2\/categories?post=2970"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artru.net\/en\/wp-json\/wp\/v2\/tags?post=2970"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}