当前位置: 首页 > 后端技术 > Node.js

从零开始搭建一个Hexo个人博客

时间:2023-04-03 19:01:54 Node.js

序大专。我在高中的时候就对Android系统很感兴趣。从简单的ROM打包=>修改smali=>JAVA=>Android=>逆向分析(JAVA层),现在已经入了Spring全家桶的坑不能自拔了。感觉有点偏离初衷。效果https://dhbin.cn环境配置环境:阿里云Ubuntu16.04installgit$aptupdate$aptinstallgit-coreinstallNodejs安装Node.js最好的方式是使用nvm$wgethttps://raw。github.com/creationix/nvm/master/install.sh$sudochmod+xinstall.sh$./install.sh执行nvm可能会提示找不到命令,执行$source~/.bashrc安装完成后,重启终端并执行以下命令安装Node.js。$nvminstallstable安装Hexo$npminstall-ghexo-cli安装Nginx$aptinstallnginx如果系统中没有Nginx源,百度上有很多建站教程安装好Hexo后,执行以下命令,Hexo会在指定的文件夹中创建所需的文件。$hexoinit$cd$npminstall安装完成后,执行$hexoserver输出:INFOStartprocessingINFOHexoisrunningathttp://localhost:4000/。按Ctrl+C停止。可以访问配置Hexo配置在Hexo文档中对配置信息有非常详细的描述。这里主要说一下我修改的本地配置文件:_confg.yml#sitetitle:titlesubtitle:subtitledescription:descriptionkeywords:keywords,对于SEOauthor:authorlanguage:language,我这里配置zh-CNtimezone:timezone#URL##如果你的网站放在子目录下,url设置为'http://yoursite.com/child',root设置为'/child/'url:网站permalink:文章的永久链接格式是我的配置:year/:month/:day/:id.html#如果使用:id,执行hexoclean会改变NexT的配置,下载NexT,这里我是下载而不是gitclone,因为用git托管整个的时候会有冲突项目。如果您在github上托管项目,则可以将NexT添加为子模块。$cd$gitsubmoduleaddhttps://github.com/theme-next/hexo-theme-nextthemes/next修改/_config.yml,切换主题为next#Extensions##Plugins:https://hexo.io/plugins/##Themes:https://hexo.io/themes/theme:nextCustomizeNexTModify/themes/next/_config.yml#Changeheadershierarchyonsite-subtitle(将是主要网站描述)和所有帖子/页面标题以获得更好的SEO优化。seo:true#seooptimization#Menumenu:home:/||主页#about:/about/||用户标签:/tags/||标签类别:/categories/||第档案馆:/archives/||归档#schedule:/schedule/||日历#sitemap:/sitemap.xml||站点地图#commonweal:/404/||heartbeat#Enable/Disablemenuicons/itembadges.menu_settings:icons:truebadges:true#打开后菜单显示徽章总数#schemes样式,NexT提供了四种,我觉得Mist比较顺眼#scheme:Musescheme:Mist#scheme:Pisces#scheme:Gemini#SocialLinks.#Usage:`Key:permalink||icon`#Key是显示给最终用户的链接标签。#`||`之前的值delimeter是目标永久链接。#`||`分隔符后的值是FontAwesome图标的名称。如果未指定图标(带或不带分隔符),将加载地球图标。#格式:#显示名称:链接||图标社交:GitHub:https://github.com/DHBin||githubGitee:https://gitee.com/FYMD||code#侧边栏头像#头像可以是在线链接,也可以是本地头像:#自动摘录。不推荐。#请在帖子中使用来准确控制摘录。#这里没有修改,可以使用显示摘要#如:#---#IamAbstract##只在首页显示“IamAbstract”auto_excerpt:enable:falselength:150#Canvas-nest#Dependencies:https://github.com/theme-next/theme-next-canvas-nest#背景动画canvas_nest:true#ScriptVendors.#为您要自定义的供应商设置CDN地址。#例如#jquery:https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js#请注意,您应该使用与内部版本相同的版本,以避免潜在的问题。#请使用ht当您在站点上启用https时,CDN文件的tps协议。#使用CDN加速供应商:jquery:https://cdn.bootcss.com/jquery/2.1.3/jquery.min.jsfastclick:https://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js速度:https://cdn.bootcss.com/velocity/1.2.1/velocity.min.jsvelocity_ui:https://cdn.bootcss.com/velocity/1.2.1/velocity.ui.min.js步伐:https://cdn.bootcss.com/pace/1.0.2/pace.min.jspace_css:https://cdn.bootcss.com/pace/1.0.2/themes/blue/pace-theme-flash.min.csscanvas_nest:https://cdn.bootcss.com/canvas-nest.js/1.0.1/canvas-nest.min.js部署配置这里是基本完成,部署项目到服务器PM2PM2是一个节点进程管理工具。我分别运行hexoserver和自动gitpull脚本,运行hexoserver.ecosystem.config.jsmodule.exports={apps:[{name:'blog',script:'/root/.nvm/versions/node/v10.8.0/bin/hexo',instances:'max',args:['server','-p','8080','-i','127.0.0.1'],exec_mode:'cluster',watch:['scaffolds','source','themes','_config.yml'],ignore_watch:['node_modules','package.json','package-lock.json']}],};Instancessetmax,看你的实际情况设置strat.sh#!/bin/bashpm2startecosystem.config.jspm2showblogwhiletruedoecho'=====gitpull======'gitpullecho'=====gitpull======'sleep60done每次更新gitpush都会自动更新,每分钟执行一次gitpull,也可以使用webhook来实现。nginx/etc/nginx/conf.d/blog.confserver{server_namexxxx.cnlisten80;位置/{proxy_passhttp://localhost:8080;proxy_set_header主机$host;proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;}}运行$cd$chmod+xstart.sh$pm2startstart.sh其他HTTPS证书可以在https://letsencrypt.org/免费申请一个Markdown工具推荐Typora可能有错误不清楚文中有描述,请指出并交流。参考资料好用的markdown工具——typoraHexo官方文档nexT官方文档