博客手札:人生第好几次想搞博客

蓝色大肥鱼:这篇文章记录了作者在 2020 年底重新开始写博客的经过。作者放下自己开发博客和 Markdown 编辑器的执念,选择 Hexo + Fluid 快速搭建,并记录了在宝塔面板安装 Hexo、修改 hexo-server 源码让服务监听 0.0.0.0,以及最终上线的过程。

AI 摘要 DeepSeek v4.1 Flash

本文最后更新于 2026年11月10日 下午

具体是第几次,已经无从考究啦。一直执着于自己写,自己开发博客和 MarkDown 编辑器,但一直碌碌无为。在不写博客我就老了,截止今天(2020-12-22)我已经22岁了,没精力折腾了。这次下定决心啦,直接用成熟的博客产品。访问了几个博客,最终选择了 Hexo ,以 Fluid 主题作为基础。

感谢前辈们:七夏浅笑、DIYdog

约定

> 表示执行 shell 命令

# 表示注释

安装 Hexo

我是使用是虚拟机 + Linux宝塔面板,虚拟机和宝塔的安装这里就不赘述了。请看我的教程:【web实战】Linux宝塔面板安装、【web实战】开发环境 - 虚拟机安装。

Hexo 官网:https://hexo.io/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 安装Hexo脚手架
> npm i -g hexo-cli

+ hexo-cli@4.2.0
added 65 packages from 334 contributors in 4.085s

# 进入宝塔web根目录
> cd /www/wwwroot

# 初始化Hexo项目
> hexo init example.com

INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
INFO Install dependencies
INFO Start blogging with Hexo!

# 运行Hexo
> hexo server -i 0.0.0.0

INFO Validating config
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.

到此,Hexo就安装完成了。

但不是我想要的效果,指定ip为0.0.0.0被替换了。

解决ip问题

直接翻阅hexo-server源代码,找到了问题所在。

文件:node_modules/hexo-server/lib/server.js

1
2
3
4
5
6
7
8
function formatAddress(ip, port, root) {
let hostname = ip;
if (ip === '0.0.0.0' || ip === '::') {
hostname = 'localhost';
}

return url.format({protocol: 'http', hostname: hostname, port: port, path: root});
}

Hexo 团队为什么这么做呢,可能是为了所谓的安全吧。

翻阅 server.js 的 Commit History,找到了对应修改记录。

Commit 4103a759e4

Add options and some improvements

  • Add “compress” option: Enable GZIP compression
  • Add “header” option: Add “X-Powered-By: Hexo” header
  • Display “0.0.0.0” as “localhost”
  • Use supertest-promised in tests

Commit 5efada50ab

Serve on all interfaces by default

This commit changes the default value of the --ip option to use
Node’s internal resolution. It means that it will try to bind to
the unspecified IPv6 address :: if available or else fall back to the
unspecified IPv4 address 0.0.0.0. In most systems, :: also binds
to 0.0.0.0 which effectively allows to listen on all interfaces.

找到了重点:Display “0.0.0.0” as “localhost”

这个做法就是不让外网访问,为了小白而考虑的所谓的安全。

不会吧,不会真有人不使用静态访问吧?!

直接把替换判断注释掉就可以了。

1
2
3
4
5
6
7
8
function formatAddress(ip, port, root) {
let hostname = ip;
// if (ip === '0.0.0.0' || ip === '::') {
// hostname = 'localhost';
// }

return url.format({protocol: 'http', hostname: hostname, port: port, path: root});
}

最终成果

最终成果


博客手札:人生第好几次想搞博客
https://www.vlice.cn/po/84d8a836d176/
作者
Violet_ice紫冰
发布于
2020年12月22日
更新于
2026年11月10日
许可协议