搭建属于自己的网站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

相关推荐
Wang's Blog3 小时前
Linux小课堂: 网络接口与连接监控命令详解
linux·运维·服务器
哈喽哈喽哈喽~3 小时前
推送文件到github ---服务器关键配置内容
运维·服务器·经验分享·github
天上飞的粉红小猪3 小时前
linux的文件系统
linux·运维·服务器·1024程序员节
雪中何以赠君别4 小时前
【框架】CLI 工具笔记
javascript·node.js
m0_748240255 小时前
基于Reactor模式的高性能C++仿Muduo库:Server服务器模块实现
服务器·c++·php
技术爬爬虾5 小时前
AI编程新王Codex详细攻略,一期视频精通,附免费使用方法
程序员·github
王同学_1165 小时前
Linux系统端口关闭并排查相关自启动项(麒麟环境)
linux·运维·服务器
q9085447035 小时前
Prometheus+Grafana 智能监控告警系统(服务器指标采集、mysql指标采集)
服务器·grafana·prometheus
郝学胜-神的一滴5 小时前
使用 Python 元类与属性实现惰性加载:Effective Python 第47条
linux·服务器·开发语言·python