aboutsummaryrefslogtreecommitdiff
path: root/content/blog/2020-08-22-redirect-github-pages.org
diff options
context:
space:
mode:
authorChristian Cleberg <hello@cleberg.net>2024-04-22 14:07:21 -0500
committerChristian Cleberg <hello@cleberg.net>2024-04-22 14:07:21 -0500
commit3def68d80edf87e28473609c31970507d9f03467 (patch)
treea64fb6363727dbfba4125d1b3c9d5c1423019b5e /content/blog/2020-08-22-redirect-github-pages.org
parent9ad1dcee850864fd2c8564ac90e4154ce68ae2b8 (diff)
downloadcleberg.net-3def68d80edf87e28473609c31970507d9f03467.tar.gz
cleberg.net-3def68d80edf87e28473609c31970507d9f03467.tar.bz2
cleberg.net-3def68d80edf87e28473609c31970507d9f03467.zip
format a portion of blog posts
Diffstat (limited to 'content/blog/2020-08-22-redirect-github-pages.org')
-rw-r--r--content/blog/2020-08-22-redirect-github-pages.org106
1 files changed, 48 insertions, 58 deletions
diff --git a/content/blog/2020-08-22-redirect-github-pages.org b/content/blog/2020-08-22-redirect-github-pages.org
index cae5928..562249d 100644
--- a/content/blog/2020-08-22-redirect-github-pages.org
+++ b/content/blog/2020-08-22-redirect-github-pages.org
@@ -5,17 +5,16 @@
* Short answer
** Step 1
-Add a new file CNAME to your GitHub Pages repository containing only one
-line: your top-level domain name. E.g.: =example.com=
+Add a new file CNAME to your GitHub Pages repository containing only one line:
+your top-level domain name. E.g.: =example.com=
** Step 2
[Optional] but highly recommended
-2.1: Remove all other top-level records (prefixed with @) of type A from
-your DNS configuration.
+2.1: Remove all other top-level records (prefixed with @) of type A from your
+DNS configuration.
-2.2: Remove a CNAME record for the second-level domain www if it is
-present.
+2.2: Remove a CNAME record for the second-level domain www if it is present.
** Step 3
Add these 5 entries to the very top of your DNS configuration:
@@ -35,52 +34,48 @@ Wait for your DNS changes to propagate. DNS changes aren't effective
immediately. They can take up to a full day to propagate.
* Long answer
-This issue has two sides. One is the DNS configuration itself. Another
-one is the way GitHub Pages will forward HTTP requests.
+This issue has two sides. One is the DNS configuration itself. Another one is
+the way GitHub Pages will forward HTTP requests.
-We need to know a few things to understand what GitHub is trying to say
-in their documentation.
+We need to know a few things to understand what GitHub is trying to say in their
+documentation.
** DNS Entry Types
There are two types of DNS records which interest us: CNAME and A.
-=A= is also known as =Apex= or sometimes as =root entry=. It forwards
-requests to a specified fixed IP address. =CNAME= entry forwards
-requests to a specified URL (actual valid plain text URL, not an IP
-address).
+=A= is also known as =Apex= or sometimes as =root entry=. It forwards requests
+to a specified fixed IP address. =CNAME= entry forwards requests to a specified
+URL (actual valid plain text URL, not an IP address).
** DNS Load balancing
-GitHub has one central URL address which accepts all DNS requests for
-GitHub Pages: =http://username.github.io=. That URL is resolved to
-different IP addresses based on your geographical location. Website
-hosted on GitHub Pages is a simple collection of =HTML=, =CSS= and =JS=
-files. GitHub distributes these files to different servers across the
-globe. So that when your browser sends a request from Europe, it
-receives data from a server in Europe. The same is valid for the
-requests from Asia and the USA.
+GitHub has one central URL address which accepts all DNS requests for GitHub
+Pages: =http://username.github.io=. That URL is resolved to different IP
+addresses based on your geographical location. Website hosted on GitHub Pages is
+a simple collection of =HTML=, =CSS= and =JS= files. GitHub distributes these
+files to different servers across the globe. So that when your browser sends a
+request from Europe, it receives data from a server in Europe. The same is valid
+for the requests from Asia and the USA.
** What GitHub is trying to say
-Since =A= records in DNS must contain IP addresses, and they must be
-either =185.199.108.153= or =185.199.109.153= or =185.199.110.153= or
-=185.199.111.153=, there is no way to forward requests to a server
-located somewhere in Europe or Asia. Your website hosted at GitHub Pages
-will be downloaded from a central GitHub Pages server. There is a minor
-risk that if GitHub Pages DNS servers (=x.x.x.153=) are down for some
-reason, all custom domains which use fixed GitHub Pages IP addresses
-will not be accessible (their DNS requests will not be resolvable).
-
-That is why GitHub strongly suggests to either use a second-level domain
-for your GitHub Pages (e.g. =blog.example.com=) or use a DNS service
-provider that supports a record type =ALIAS= that acts as =A= record but
-forwards request to a URL address (e.g. =username.github.io=) instead of
-a fixed IP address.
+Since =A= records in DNS must contain IP addresses, and they must be either
+=185.199.108.153= or =185.199.109.153= or =185.199.110.153= or
+=185.199.111.153=, there is no way to forward requests to a server located
+somewhere in Europe or Asia. Your website hosted at GitHub Pages will be
+downloaded from a central GitHub Pages server. There is a minor risk that if
+GitHub Pages DNS servers (=x.x.x.153=) are down for some reason, all custom
+domains which use fixed GitHub Pages IP addresses will not be accessible (their
+DNS requests will not be resolvable).
+
+That is why GitHub strongly suggests to either use a second-level domain for
+your GitHub Pages (e.g. =blog.example.com=) or use a DNS service provider that
+supports a record type =ALIAS= that acts as =A= record but forwards request to a
+URL address (e.g. =username.github.io=) instead of a fixed IP address.
** How GitHub Pages treats HTTP requests
-After a DNS request for =your_github_username.github.io= is resolved
-into an IP address, e.g. =185.199.108.153= your browser sends an HTTP
-request to that server with an HTTP header =Host=. Below are =curl=
-examples that load the same website (these examples might not work if
-you are behind a proxy server):
+After a DNS request for =your_github_username.github.io= is resolved into an IP
+address, e.g. =185.199.108.153= your browser sends an HTTP request to that
+server with an HTTP header =Host=. Below are =curl= examples that load the same
+website (these examples might not work if you are behind a proxy server):
#+begin_src sh
curl --header "Host: your_github_username.github.io" http://185.199.108.153/
@@ -91,30 +86,25 @@ curl --header "Host: example.com" http://185.199.108.153/
This way GitHub Pages servers know which user website to serve.
#+begin_quote
-GitHub Pages server will automatically redirect HTTP requests to the
-top-level domain if your =CNAME= file contains =example.com= but
-=www.example.com= is requested.
+GitHub Pages server will automatically redirect HTTP requests to the top-level
+domain if your =CNAME= file contains =example.com= but =www.example.com= is
+requested.
-The same is valid if your =CNAME= file contains =www.example.com= but
-the header =Host= in the =HTTP= request contains =example.com=.
+The same is valid if your =CNAME= file contains =www.example.com= but the header
+=Host= in the =HTTP= request contains =example.com=.
#+end_quote
** Why can't I add a =CNAME= record entry that accepts a top-level request (=@=) to my DNS configuration?
Quote from the GitHub Pages documentation:
#+begin_quote
-Warning: Do not create a CNAME record for your custom apex domain! Doing
-so may cause issues with other services, such as email, on that domain.
+Warning: Do not create a CNAME record for your custom apex domain! Doing so may
+cause issues with other services, such as email, on that domain.
#+end_quote
** References:
-1. [[https://docs.github.com/en/github/working-with-github-pages/configuring-a-custom-domain-for-your-github-pages-site][Setting
- up a custom domain with GitHub Pages]]
-2. [[https://docs.github.com/en/github/working-with-github-pages/troubleshooting-custom-domains-and-github-pages][My
- custom domain isn't working]]
-3. [[https://serverfault.com/questions/589370/cannot-access-my-github-pages-website-by-ip-address][Cannot
- access my GitHub Pages website by IP Address]]
-4. [[https://stackoverflow.com/questions/23375422/how-do-i-set-up-github-pages-to-redirect-dns-requests-from-a-subdomain-e-g-www][How
- do I set up GitHub Pages to redirect DNS requests from a subdomain
- (e.g. www) to the top-level domain (TLD, Apex record)?]]
-
+1. [[https://docs.github.com/en/github/working-with-github-pages/configuring-a-custom-domain-for-your-github-pages-site][Setting up a custom domain with GitHub Pages]]
+2. [[https://docs.github.com/en/github/working-with-github-pages/troubleshooting-custom-domains-and-github-pages][My custom domain isn't working]]
+3. [[https://serverfault.com/questions/589370/cannot-access-my-github-pages-website-by-ip-address][Cannot access my GitHub Pages website by IP Address]]
+4. [[https://stackoverflow.com/questions/23375422/how-do-i-set-up-github-pages-to-redirect-dns-requests-from-a-subdomain-e-g-www][How do I set up GitHub Pages to redirect DNS requests from a subdomain (e.g.
+ www) to the top-level domain (TLD, Apex record)?]]