博客域名更换操做记录

拖延了半年后,我终于在最近把个人域名 shanyue.tech 经过了备案。新域名能够更好的贴合个人博客,趁此对个人域名进行更换html

若是刚开始就使用新域名,却是很简单。可是更换域名就须要作一些额外的琐碎的东西了,记录一下nginx

本文地址 shanyue.tech/post/domain…git

https

在制做证书时在 domains 中添加新域名github

certbot -d shanyue.tech -d xiange.tech -d *.shanyue.tech -d *.xiange.tech ...
复制代码

reverse proxy

在反向代理中使用新域名代替旧有域名,如下是 traefik 在 docker 的 compose file 的示例docker

version: "3"
services:
 blog:
 build:
 context: .
 restart: always
 labels:
 - "traefik.old.frontend.rule=Host:blog.xiange.tech"
 - "traefik.blog.frontend.rule=Host:shanyue.tech"
复制代码

301 & SEO

为了防止使用旧网址打开失败,须要进行301重定向,重定向以前思考两个问题shell

  1. 为何不使用 302
  2. 为何不给站点设置多个 domain

答案是为了 SEO,使用 301 能够把搜索引擎原域名的收录给带过去,而使用多个 domain 会下降页面的权重frontend

百度给的建议是新旧网站并存一段时间,而后进行 301dom

version: "3"
services:
 blog:
 build:
 context: .
 restart: always
 labels:
 - "traefik.old.frontend.rule=Host:blog.xiange.tech"
 - "traefik.old.frontend.redirect.regex=^https?://blog.xiange.tech/(.*)"
 - "traefik.old.frontend.redirect.replacement=https://shanyue.tech/$$1"
 - "traefik.old.frontend.redirect.permanent=true"
复制代码

sitemap.xml & robots.txt

这两个是为了 SEO,若是你没有此类需求,则不用改这块post

当站点新添了页面,能够使用 sitmeap 更好地通知搜索引擎的小蜘蛛们,方便新页面更快的收录网站

须要更改 sitemap 中 的 url.loc 的绝对地址为新域名,如下是一个 sitemap 的样例,你也能够经过 shanyue.tech/sitemap.xml 访问

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>https://blog.xiange.tech/post/login-input-style/</loc>
    <lastmod>2019-04-23T11:12:38+08:00</lastmod>
  </url>`
</urlset>
复制代码

依赖应用

在我博客的评论系统中使用了 github 的 OAuth Apps,须要更改主页及回调地址

  • Homepage URL
  • Authorization callback URL

总结

鉴于只是一个简单的博客,应该没有什么工做量了

若是域名须要 SEO,也就比较麻烦些,若是不须要的话,基本能够使用 nginx 或者 traefik 配置多个域名就能够了

相关文章
相关标签/搜索