搭建属于自己的网站HEXO静态页(二)发布网站到gihub

配置发布到github

安装插件并修改配置

复制代码
npm install hexo-deployer-git --save

配置_config.xml,修改如下内容

复制代码
deploy:
  type: git
  repo:  git@github.com:it-xusir/it-xusir.github.io.git
  branch: master

repo替换成你的github新建的repo

branch默认master就可以

配置github仓库

进入官网 https://github.com/

点击右上角的 Sign up(注册),不是Sign in(登录)。

填写自己的邮箱、密码、用户名等信息,然后用邮箱验证即可完成。

创建仓库

点击右上角的+按钮,选择New repository,创建一个<用户名>.github.io的仓库

找不到创建入口的,访问:https://github.com/new

仓库的格式必须为:<用户名>.github.io

Description:为描述仓库(选填)

注意选择public仓库

勾选 Initialize this repository with a README 初始化一个 README.md 文件

点击 Creat repository 进行创建

配置git

执行命令

复制代码
git config --global user.name "你的github用户名"  
git config --global user.email "你的邮箱"

通过git config -l 检查是否配置成功,至此git安装及配置全部完成。

复制代码
D:\it-xusir.github.io>git config -l
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=schannel
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.name=it-xusir
user.email=huiyangxu@hotmail.com
core.autocrlf=false

生成ssh公钥

复制代码
ssh-keygen -t rsa -C "你的邮箱"

之后打开C盘下用户文件夹下的.ssh的文件夹,会看到 id_rsa.pub

用记事本打开上述图片中的公钥(id_rsa.pub),复制里面的内容,然后开始在github中配置ssh密钥。

进入github,点击右上角头像 选择settings

进入设置页后选择 SSH and GPG keys

title自己起个名,然后把密钥复制粘贴到key的框内,最后add sshkey

测试

复制代码
D:\it-xusir.github.io>ssh -T git@github.com
Hi it-xusir! You've successfully authenticated, but GitHub does not provide shell access.

上传代码

还有一步配置别忘记了,把_config.xml里的url改成的你域名,如果你还没申请域名,就用github的博客地址。

复制代码
url: https://itxusir.com/

然后

复制代码
hexo clean
hexo generate
hexo deploy

每次你在本地修改完,再重复执行上面的命令,同步到github

配置域名解析

购买域名后,实名认证进入阿里云控制台,点云解析进去,找到你刚买的域名,

点进去添加两条解析记录:

1、cname记录添加,主机www,记录值就是你的github博客地址(我这里是it-xusir.github.io

2、添加A记录, 主机记录@,记录值填github的IP地址(185.199.111.153、185.199.110.153、185.199.109.153、185.199.108.153)

打开博客/source目录,我的是D:\it-xusir.github.io\source,新建CNAME文件,注意没有后缀。然后在里面写上你的域名(例如:itxusir.com),保存。最后运行hexo g、hexo d上传到github。这样到最后当你在地址栏输入xxx.github.io时,才会自动跳转到你的域名。

打开你的github博客项目,点击settings,点击Pages,拉到下面Custom domain处,填上你自己的域名 ,保存。

最后勾选enforcehttps记录。让你的网站变成HTTPS

相关推荐
zzqssliu5 小时前
煤炉自动代拍系统的队列设计与超时控制机制
git·github
fthux8 小时前
“装闭”,让装修套路“装”不下去
人工智能·ai·开源·github·open source
吳所畏惧9 小时前
宝塔面板Redis密码修改指南:SSH命令修改 vs 面板UI界面修改,哪个更靠谱?
运维·服务器·数据库·redis·缓存·ssh
DFT计算杂谈10 小时前
无 Root 权限在 Tesla K80 零门槛部署 DeepSeek 大模型
linux·服务器·网络·数据库·机器学习
维天说10 小时前
CLI-Switch 2026年3月版历史设计:Hook、TTY 隔离与 JSON 状态
java·服务器·json
Zhang~Ling11 小时前
从 fopen 到 struct file:从零开始拆解 Linux 文件 I/O
linux·运维·服务器
hoLzwEge11 小时前
拯救低效调试!code-inspector-plugin 让代码定位如虎添翼
前端·前端框架·node.js
爱写代码的阿森11 小时前
鸿蒙三方库 | harmony-utils之PreferencesUtil首选项数据监听详解
服务器·华为·harmonyos·鸿蒙·huawei
爱写代码的森11 小时前
蒙三方库 | harmony-utils之FileUtil文件重命名与属性查询详解
linux·运维·服务器·华为·harmonyos·鸿蒙·huawei
用户849137175471611 小时前
想做护眼工具却脑子一片空白?我用 OpenSpec 把模糊想法聊成了 v0.1
github·vibecoding