通常,对于绑定了顶级域名的 Hexo 博客来说,只需在所用主题的source文件夹下新建一个404.html文件,再生成部署到云端,即可生成博客404页面。但这种方法生成的页面是孤立的,下面介绍一种生成匹配主题的404页面的方法。

新建404页面
- 启动 Git Bash,进入 Hexo 所在文件夹,输入 
hexo new page 404 ; 
- 打开刚新建的页面文件,默认在 Hexo 文件夹根目录下 
/source/404/index.md; 
- 在顶部插入一行,写上
permalink: /404,这表示指定该页固定链接为 http://"主页"/404.html 
1 2 3 4 5
   | title: 404 Not Found:该页无法显示 toc: false comments: false permalink: /404 ---
   | 
 
自定义页面样式
  经过上面的设置后,404界面已生效,其编辑方式与一般文章无异。我们可以在.md文件正文中插入一些 CSS 样式,使得该页面与博客中的一般文章有所区别。下面是我个人为配合本博客主题所设置的一些样式,仅供参考,具体修改自行审查所用主题。
http://moxfive.xyz/举个404页面栗子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
   | title: 404 Not Found:该页无法显示 toc: false comments: false permalink: /404 --- <style type="text/css"> 	.article-header { 		padding: 0; 		padding-top: 26px; 		border-left: none; 		text-align: center; 	} 	.article-header:hover { 		border-left: none; 	} 	.article-title { 		font-size: 2.1em; 	} 	strong a { 		color: #747474; 	} 	.article-meta { 		display: none; 	} 	.share { 		display: none; 	} 	.ds-meta { 		display: none; 	} 	.player { 		margin-left: -10px; 	} 	.sign { 		text-align: right; 		font-style: italic; 	}   	#page-visit { 		display: none; 	} 	.center { 		text-align: center; 		height: 2.5em; 		font-weight: bold; 	} 	.article-entry hr { 		margin: 0; 	} 	.pic { 		text-align: center; 		margin: 0; 	} 	.pic br {   		display: none;   	} 	#container .article-info-post.article-info {   	display: none;   	} 	#container .article .article-title { 	padding: 0; 	} </style>
   | 
 
参考资料
- Custom 404 Pages by GitHub Help on 
2015: https://help.github.com/articles/custom-404-pages/