一、域名迁移
1.何为域名迁移?
即我有原域名AAA.com下的一个wp博客网站,但是这个AAA.com域名要到期了或者有自己更喜欢的域名,则需要对域名进行迁移操作。
2.迁移过程
由于宝塔网站设置的限制存在,在这里选用的是先使用宝塔自带的功能备份站点及数据库,完成后将原站点及其配套的数据库删除。重新新建一个域名为BBB.com的新网站(即使用你想更换的域名建站)。值得注意的是,在删除网站时其实不需要删除数据库,这里只是为了保证严谨。然后在www/backup/site目录下找到之前的网站备份压缩包,将其解压到新建的网站的根目录下。(详情请谷歌宝塔wordpress备份恢复)
完成上面步骤后,修改新建的站点的权限为755并勾选包含子文件夹选项。修改wp_config.php中的数据库相关信息,重启nginx即可。(固定链接伪静态、ssl证书要重新配置)
附:伪静态代码:
location /
{
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
3.在迁移过程中出现了什么问题?
问题一:出现403 Forbiden nginx 错误:
解决方案:
使用ping工具查看域名解析情况,发现已经正常解析,但是仍出现一直403的情况。后来发现403是重定向至原域名下的403错误,而非新域名下的错误。初步排查和cf解析无关,与ssl证书也无关。在修改数据库表项之后应该不会再重定向过去,检查重定向也没有记录。怀疑为really simple ssl等插件导致的重定向,疑惑了很久以后通过强制设定主页网址解决。即在wp_config.php的末尾加入代码:
define('WP_HOME','https://oliverhou.com');
define('WP_SITEURL','https://oliverhou.com');
问题二:变更cloudflare解析后仍解析至原域名,但是原域名证书和解析记录已被删除,导致直接报错DNS ERROR 1016
解决方案:
原先是讲旧域名解析记录直接删除,在新域名处添加新纪录。但是不知为何需要将旧域名修改指向再删除才生效,可能是修改可以设置TTL为一分钟可以马上生效的原因。故修改旧域名指向后再删除,随后错误变为问题一
还有关于插件等问题未提及但是也仍需注意。同时在迁移时需要使用SQL语句修改域名关键信息,参考代码:
UPDATE wp_options SET option_value = replace(option_value, 'old_domain.com', 'new_domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, 'old_domain.com', 'new_domain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'old_domain.com', 'new_domain.com');
UPDATE wp_comments SET comment_content = replace(comment_content , 'old_domain.com', 'new_domain.com');
上述代码参考网站(网站内还有别的情况的代码):
Hello this iis kida oof ooff topic but I was wondering if blogs use
WYSIWYG editors orr if yoou haqve to manually codde with HTML.
I’m starting a blog soon but have nno coding skills so
I wahted to get guidance frokm someeone with experience.
Any help would bbe greatly appreciated!
Hey there! Would you mind if I sharfe your blog wityh my ynga group?
There’s a lott oof folks that I thonk would really appreciate your
content. Please leet mme know. Many thanks
Thiis article wull assist the iternet viewers forr building up new wweb site or evven a blkog from start too end.
Hi thede too all, hhow is all, I think evfery one is getting more fdom this site, annd yor views aare pleasant for
new visitors.
I’ve been exploring for a ittle bit for anyy higbh quality articles or
weblog posts on thbis sordt oof area . Exploring inn Yahhoo I finalloy
stumbled upon this web site. Studying this info So i’m hqppy tto show that I’ve a very good unanny
feeling I found outt exactly whaqt I needed. I soo much no doubt will make suree to don?t disdegard this website and give it a look regularly.
If yoou wish forr tto grow your knowledge only kee visiting this
weeb page annd be updatfed with the newest infoirmation posted here.
I’ve been eexploring for a little bit ffor aany hugh
quality articles or blog poosts in thijs kind oof are .
Exploring in Yhoo I finally stumbled upon ths site. Studyiong this information So i am glad to exhibiit
that I have an incredibly excelolent uncajny feeling I found oout exactlly whaqt I needed.
I soo mch withoiut a douibt will maqke certainn too don?t overlokk this ite and provides it
a lookk regularly.