[hexo-server]
随着 Hexo 3 的发布,服务器已与主模块分离。要开始使用服务器,你首先必须安装 hexo-server。
¥With the release of Hexo 3, the server has been separated from the main module. To start using the server, you will first have to install hexo-server.
$ npm install hexo-server --save |
安装服务器后,运行以下命令启动服务器。你的网站默认在 http://localhost:4000
运行。当服务器运行时,Hexo 会监视文件更改并自动更新,因此无需手动重启服务器。
¥Once the server has been installed, run the following command to start the server. Your website will run at http://localhost:4000
by default. When the server is running, Hexo will watch for file changes and update automatically so it’s not necessary to manually restart the server.
$ hexo server |
如果你想要更改端口或遇到 EADDRINUSE
错误,请使用 -p
选项设置其他端口。
¥If you want to change the port or if you’re encountering EADDRINUSE
errors, use the -p
option to set a different port.
$ hexo server -p 5000 |
静态模式
¥Static Mode
在静态模式下,只会提供 public
文件夹中的文件,并且文件监视被禁用。你必须在启动服务器之前运行 hexo generate
。通常在生产中使用。
¥In static mode, only files in the public
folder will be served and file watching is disabled. You have to run hexo generate
before starting the server. Usually used in production.
$ hexo server -s |
自定义 IP
¥Custom IP
Hexo 默认在 0.0.0.0
运行服务器。你可以覆盖默认的 IP 设置。
¥Hexo runs the server at 0.0.0.0
by default. You can override the default IP setting.
$ hexo server -i 192.168.1.1 |