Skip to content

1、实战-docker部署twikoo-20250308(测试成功)

image-20250308104305295

实战-docker部署twikoo-20250308(测试成功)

目录

[toc]

版权

警告

本着开源共享、共同学习的精神:

本文是在 博主《从 01 开始》文章:《评论区》基础上增加了一些自己的实际操作记录和修改,内容依旧属于原作者《从 01 开始》所有。转载无需和我联系,但请注明文章来源。如果侵权之处,请联系博主进行删除,谢谢~(这里万分感谢原作者的优质文章😜,感谢开源,拥抱开源💖)

说明:

次配置是基于自己的开源网站 《vuepress-theme-vdoing-one-public》测试的,请注意。

此模板是在Young Kbt blog的开源项目《Kele-Bingtang.github.io》基础上修改为自己的风格而成,感谢大佬开源的模板&感谢原作者开源的vdoing主题。❤️❤️

环境

bash
twikooversion":"1.6.41vdoing网站(vuepress)centos7.xdocker环境
  • 源码

通过网盘分享的文件:2025.3.8-实战-docker部署twikoo-20250308(测试成功) 链接:https:cat>>/root/twikoo/docker-compose.yaml<<EOFversion:'3'services:twikoo:image:imaegoo/twikoocontainer_name:twikoorestart:unless-stoppedports:- 8080:8080environment:TWIKOO_THROTTLE:1000volumes:- ./data:/app/dataEOFcd/root/twikoodocker-composeup-d


https:[root@wiki twikoo]# lsdatadocker-compose.yaml[root@wiki twikoo]# ls data/db.jsondb.json.0db.json.1db.json.2[root@wiki twikoo]#

2、配置 https

理论上这样部署,就完成后台的部分了,但鉴于我的网站用了 HTTPS,而 Twikoo 本身并不支持,因此还需要做反向代理

接下来的步骤如下:

  1. 再申请和购买一个 SSL 证书
  2. 配置 cname
  3. 下载证书放到 Linux 服务器上
  4. 配置 Nginx 反向代理

购买 HTTPS 证书,这里我用二级域名的:

image-20241223223631415

然后在云服务器控制台上配置 cname:

image-20241223223647803

‍我的配置:

image-20241223223820340

  • 我的配置:(注意作者和我这里的配置哦😜😜😜)
bash
cd/etc/nginx/conf.d/vimtwikoo.onedayxyy.cn.conf[root@docusaurus-wiki conf.d]# cat twikoo.onedayxyy.cn.conf server{listen80;server_nametwikoo.onedayxyy.cn;#配置https重定向return301https:}server{listen443ssl;server_nametwikoo.onedayxyy.cn;location/{proxy_passhttp:client_max_body_size100M;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;proxy_set_headerX-Forwarded-Proto$scheme;} ssl_certificate/etc/letsencrypt/live/onedayxyy.cn/fullchain.pem;ssl_certificate_key/etc/letsencrypt/live/onedayxyy.cn/privkey.pem;ssl_session_timeout5m;ssl_protocolsTLSv1.1TLSv1.2TLSv1.3;ssl_ciphersEECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;ssl_prefer_server_cipherson;add_headerStrict-Transport-Security"max-age=31536000";access_log/var/log/nginx/photo.onedayxyy.cn.https.log;}nginx-t
  • 重启下nginx

nginx -s reload

  • 验证

https:我的配置:#本次实际配置['script',{src:'https:<scriptsrc="https:<script>

https:<divid="tcomment"></div></template><script>letwaitTime =700;letarchives ="/archives/";exportdefault{data() {return{twikoo:"",firstLoad:true,};},mounted() {if((this.$frontmatter.comment ==undefined||this.$frontmatter.comment) &&this.$route.path !="/"&&this.$route.path !=archives &&!this.isFourZeroFour(this.$route)) {setTimeout(() =>{this.twikooInit();},waitTime);}},watch:{$route(to,from) {if(this.$route.path =="/"||this.$route.hash !=""||this.isFourZeroFour(to)) {return;}if(to.path =="/"||this.getCommentByFrontmatter(to) ==false) {this.deleteComment();return;}if(from.path =="/"||from.path ==archives ||!this.getCommentByFrontmatter(from)) {this.firstLoad?setTimeout(() =>{this.twikooInit();this.firstLoad =false;},waitTime):this.twikooInit();} elseif(this.$route.path !="/"&&this.$route.hash =="") {setTimeout(() =>{this.updateComment();},waitTime);}},},methods:{twikooInit() {twikoo.init({envId:"https:el:"#tcomment",}).then(() =>{this.loadTwikoo();});},loadTwikoo() {letpage =document.getElementsByClassName("page")[0];letcomment =document.getElementById("twikoo");comment ?(this.twikoo =comment) :(comment =this.twikoo);page?comment?page.appendChild(comment):page.appendChild(this.twikoo):"";this.updateComment();},updateComment() {lettk_icon =document.getElementsByClassName("tk-icon")[0];tk_icon ?tk_icon.click() :undefined;},deleteComment() {letcomment =document.getElementById("twikoo");comment ?comment.parentNode.removeChild(comment) :"";},getCommentByFrontmatter(route) {letcomment =true;this.$site.pages.forEach((item) =>{if(item.path ==route.path) {comment =item.frontmatter.comment;}});returncomment;},isFourZeroFour(route) {letflag =true;this.$site.pages.forEach((item) =>{if(item.path ==route.path) {flag =false;}});returnflag;},},};</script><style>.twikoo.tk-comments{margin-top:20px;}</style>

03地方配置

参考这里:

https:plugins:<UserPlugins>[[{name:'custom-plugins',globalUIComponents:["Twikoo"] }]]

image-20250308115348895

04注释原来评论插件

image-20241223231509388

  • 自己版本配置

image-20250308115127670

4、效果

完美。🤣

image-20241223231534152

image-20241223232022232

配置完之后,就注册下,要记住密码。

后续步骤进很简单了。😜

FAQ

官网:https:$ ln -s /opt/nodejs/node/bin/tkserver /usr/local/bin/tkserver$ tkserver

然后就可以访问了,地址是:http:t="1711730357270" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4392" width="16" height="16" >打赏支持