appotry / docker-hexo

hexo docker 一键部署环境。增加CJK中国环境适配和常用软件,hexo 插件等易用设置。开箱即用。
90 stars 14 forks source link

hexo服务没有正常运行 #22

Closed CheFng closed 1 month ago

CheFng commented 1 month ago

我在群晖DSM7.2环境下的docker中创建了bloodstar/hexo这个镜像的一个容器并运行了它,但是我发现无法在浏览器直接通过localhost:4000访问网站,提示ERR_EMPTY_RESPONSE。 我觉得应该是创建容器后还需要手动开启服务,于是我进入容器内部使用了hexo server命令试图启动服务,结果报错以下内容:

(node:7501) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Pl ease use a userland alternative instead. (Use `node --trace-deprecation ...` to show where the warning was created)
Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html

并且在容器的日志中一直打印 0|hexo_run | exec error: ${error} 请问这是什么问题呢,麻烦您抽空回复一下我,感激不尽

CheFng commented 1 month ago

我自行搜索过相关问题,有说是在 nodejs v21.0.0 以上会出现以上提示,但是我没记错的话,这个镜像本身自带了nodejs v21.0.0,如果会有这种情况,为什么我并没有看到相关的说明,请原谅我的粗心,教程太过详细让我有些无从下手。

appotry commented 1 month ago

镜像运行起来之后,不需要手动hexo server来开启web服务,默认在启动脚本里面自动开启的。再次手动运行hexo server反而会报错。 另外上面punycode报错目前来说只是个警告,不影响使用

容器运行起来之后,下载主题,基本配置,然后hexo g之后应该就可以通过web端口访问了 或者直接在容器里面curl -v localhost:4000 测试一下web是否正常。注意,如果主题或者文章中有配置错误,web也是报错看不到的

CheFng commented 1 month ago

我认为我在创建容器之前的操作没有问题,容器运行起来后,进入容器内部curl -v localhost:4000之后提示 Couldn't connect t o server,然后我vi /app/userRun.sh进入文件编辑,里面只有最简单的

#!/bin/bash
echo "add User CMD here!"
echo "=====User CMD Start!====="

然后我将教程中的

# 快速添加登录github秘钥
alias github='eval "$(/usr/bin/ssh-agent -s)";/usr/bin/ssh-add ~/.ssh/id_rsa'
# 重启内部pm2 服务器
alias repm2='pm2 restart /hexo_run.js'

#### debian 中国区加速
# 如果网络速度快,可以注释
# sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

#### npm 配置
npm config ls -l

mkdir -p /app/.cache/npm
npm config set cache "/app/.cache/npm" 
# npm config set userconfig "/app/.npmrc"
# npm config set registry https://registry.npmmirror.com

npm config set registry https://registry.npmjs.org/

#### history 持久化
rm -rfv ~/.bash_history
ln -s /app/.bash_history ~/.bash_history

#### ssh 配置
#### 避免 "Are you sure you want to continue connecting (yes/no)? yes"
chmod 600 /app/.ssh/id_rsa 
chmod 644 /app/.ssh/id_rsa.pub 
chmod 700 /app/.ssh 
rm -rfv ~/.ssh
ln -s /app/.ssh ~/.ssh

#### npm 插件安装
# 这里用户可以修改自定义安装
npm install --save \
    hexo-admin \
    hexo-include-markdown \
    hexo-douban-card-new \
    hexo-github-card \
    hexo-bilibili-card-new \
    hexo-feed

增加进去后保存退出并重启了容器,通过日志观察发现这个修改是有作用的,然后我根据主页教程 微信截图_20240716173937 照做之后并在容器内部环境使用了hexo g命令,下方的教程显示可以访问,于是我通过浏览器和容器内部的curl -v localhost:4000,发现网站还是没有正常启动。 我想知道docker部署,通过镜像创建容器后,具体如何才能使得我可以访问网站并看见主页呢,主题和基本配置是必须的吗,如果是,可以给出稍微详细一点的教程吗 微信图片_20240716174832 以下是我的群晖中/docker/hexo路径下结构,映射docker中的/app路径 微信截图_20240716174854

appotry commented 1 month ago

下载完主题之后,还需要编译主题,hexo g 然后才能看到网页,使用nginx反向代理端口访问,才能使用域名访问

如果你没有配置域名反向代理,就使用端口访问来测试

CheFng commented 1 month ago

感谢解答,我放弃了docker方式部署转而在我的Centos虚拟机上安装运行,具体流程参考了Hexo入门篇,然后我配置了hexo-theme-matery主题,阅读了其README_CN.md文件,修改相关配置后,使用hexo g编译静态文件之后使用hexo s命令,成功启动了服务器,访问效果如下: image 十分感谢!