My goal is to use GitHub Pages and also benefit from their CDN, without having to use a third-party DNS host that supports DNS ALIAS record types (or ANAME - neither are accepted standards). I want to know how they do it, can anyone explain please?
We have many questions here about DNS aliasing with CNAME records, but in this particular situation I can't CNAME the naked domain to username.github.io
.
If I do this with Apache or Nginx to get www.example.com working as a GitHub Page, does it work and do I break anything like email?
Apache
<VirtualHost *:80>
ServerName example.com
Redirect 301 / http://username.github.io/
</VirtualHost>
Nginx
server {
server_name example.com;
return 301 http://username.github.io/;
}
The above assumes a CNAME for www => username.github.io and an A Record for the naked domain => one of my servers with the above configuration.
This sentence is meaningless. In both the mentioned cases, the ALIAS and ANAME custom DNS types are internally resolved into a pool of A records. Thus, from an end-user perspective, you are not breaking any standard. Any client trying to connect to a hostname you configured with an ALIAS (I can speak for DNSimple given I'm work for them) will return the same list of A record that would return the target hostname.
Theoretically you can, practically you don't want to. Per RFC, the CNAME can't co-exist with any additional record type. This means that if you CNAME the root domain you will shadow any other record associated to the root domain basically breaking your root domain capability to resolve.
You can configure
www.example.com
as CNAME as long as you don't need any other DNS record attached to that hostname. This is normally ok.From a web server configuration there is nothing you need to do. If you configure
www.example.com
as a CNAME ofusername.github.io
, any request towww.example.com
will resolve to the IP(s) associated withusername.github.io
and GitHub web servers will handle the request.Still, in this case you haven't solved the problem of what you want to do with the root domain. At this point, the only think you can do is to HTTP redirect the root domain to the
www.example.com
hostname.The configuration snippets you mentioned will work in that way.