您的位置:首页 > 编程语言

如何使用github现成的模板搭建博客

2015-05-21 11:26 106 查看
博客基于
jekyll,而新手往往摸不着头脑,幸好有一些现成的模板可以直接使用,以White
Paper这个模板为例,可以直接下载压缩包,也可以使用如下命令clone到本地:




$ git clone https://github.com/vinitkumar/white-paper.git[/code] 把克隆下来的文件拷贝到你自己的目录就行了,这样你就有一个现成的网站结构了:



通过在域名提供商那边,将你的域名指向204.232.175.78
,再在分支里面新建一个
CNAME
文件,里面写上你的域名就可以实现自定义域名了。如今github有了新的玩法



A记录:域名直接映射IP,但是这个IP换成了
192.30.252.153
192.30.252.154

如果域名提供商支持
ALIAS
ANAME
,将域名指向
username.github.io
,这样可以在域名解析的时候得到一个动态的IP,这个IP是一台离你最近的镜像主机
CNMAE:如果你希望使用二级域名访问,将一个二级域名配置成CNAME,指向
username.github.io
,这样可以在域名解析的时候得到一个动态的IP,这个IP是一台离你最近的镜像主机

其中2、3两种方式能够享受CDN加速,因为域名不是直接与IP地址映射的,github就有机会帮用户选择最近的镜像主机提供服务。但是笔者先前是直接将在A记录里面将主域
pchou.info
www.pchou.info
指向了
204.232.175.78
。这也是为什么github会给我警告的原因。但是改进有些令人发愁,因为希望保留别人对我的外链啊,那么如何改进呢?

首先删除
www.pchou.info
的A记录,添加CNAME记录

www.pchou.info -> pchou.github.io

使用dig查看域名解析情况
www.pchou.info.         1799    IN      CNAME   pchou.github.io.
pchou.github.io.        3600    IN      CNAME   github.map.fastly.net.
github.map.fastly.net.  280     IN      A       103.245.222.133


可以看到,CDN最终为我选择了IP地址为
103.245.222.133
的镜像主机

修改或添加项目中的CNAME文件,变成如下:
www.pchou.info


等待十几分钟即可。

当访问
pchou.info
的时候会自动重定向到
www.pchou.info
,于是访问一台IP为
103.245.222.133
的镜像主机
当访问
www.pchou.info
会访问一台IP为
103.245.222.133
的镜像主机

github在这里自动将
www
的子域与主域关联了起来,并有如下行为:

如果仓库的CNAME文件包含
example.com
,那么访问
www.example.com
会重定向到
example.com
如果仓库的CNAME文件包含
www.example.com
,那么访问
example.com
会重定向到
www.example.com


经过测试,使用CDN后,速度可以提高一倍:

ping最早的IP
PING 204.232.175.78 (204.232.175.78) 56(84) bytes of data.
64 bytes from 204.232.175.78: icmp_seq=1 ttl=48 time=280 ms
64 bytes from 204.232.175.78: icmp_seq=3 ttl=46 time=243 ms
64 bytes from 204.232.175.78: icmp_seq=4 ttl=48 time=273 ms
64 bytes from 204.232.175.78: icmp_seq=5 ttl=46 time=239 ms
64 bytes from 204.232.175.78: icmp_seq=6 ttl=46 time=239 ms
64 bytes from 204.232.175.78: icmp_seq=7 ttl=46 time=236 ms
64 bytes from 204.232.175.78: icmp_seq=8 ttl=46 time=238 ms


ping后来的IP
PING 192.30.252.153 (192.30.252.153) 56(84) bytes of data.
64 bytes from 192.30.252.153: icmp_seq=1 ttl=47 time=358 ms
64 bytes from 192.30.252.153: icmp_seq=2 ttl=47 time=345 ms
64 bytes from 192.30.252.153: icmp_seq=5 ttl=47 time=359 ms
64 bytes from 192.30.252.153: icmp_seq=6 ttl=47 time=351 ms
64 bytes from 192.30.252.153: icmp_seq=7 ttl=47 time=370 ms


ping动态的IP
PING 103.245.222.133 (103.245.222.133) 56(84) bytes of data.
64 bytes from 103.245.222.133: icmp_seq=1 ttl=53 time=84.5 ms
64 bytes from 103.245.222.133: icmp_seq=2 ttl=54 time=118 ms
64 bytes from 103.245.222.133: icmp_seq=3 ttl=53 time=104 ms
64 bytes from 103.245.222.133: icmp_seq=4 ttl=54 time=118 ms
64 bytes from 103.245.222.133: icmp_seq=5 ttl=53 time=104 ms
64 bytes from 103.245.222.133: icmp_seq=6 ttl=53 time=82.5 ms



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: