当前位置: 首页 > 科技观察

如何在Ubuntu上搭建Ghost博客平台?

时间:2023-03-14 15:52:19 科技观察

Ghost是一个基于Node.js的开源博客平台,由前WordPressUI负责人JohnO'Nolan和WordPress开发人员HannahWolfe创立。Internet上有许多开源博客程序。去年刚刚上线的Ghost,正在迅速俘获用户。早期的0.4.1版本让CodingHorror拥抱了Ghost。Ghost主题/模板越来越多,一些优秀的WordPress主题提供商,比如WooThemes,已经开始提供Ghost主题。安装Ghost非常简单,甚至比WordPress还要简单。以下安装步骤已在Ubuntu12.04.4LTSServer版本上测试通过。切换到root账户升级更新整个系统:$sudo-i#apt-getupdate#apt-getupgradeinstallNode.js运行环境:#apt-getinstallg++makepythonpython-software-properties#add-apt-repositoryppa:chris-lea/node.js#apt-getupdate#apt-getinstallnodejs下载、解压Ghost并安装:#cd#wgethttps://ghost.org/zip/ghost-0.4.1。zip#unzipghost-0.4.1.zip-dghost#cdghost#npminstall--production配置Ghost监听本机所有IP,修改'127.0.0.1'为'0.0.0.0':#viconfig.js。..server:{//要传递给节点的`net.Server#listen()`的主机host:'0.0.0.0',//要传递给节点的`net.Server#listen()`的端口,对于iisnode将其设置为`process.env.PORT`port:'2368'}...使用npm启动Ghost程序:#npmstart>ghost@0.4.1start/root/ghost>nodeindexGhostisrunningindevelopment...Listeningon0.0.0.0:2368Url配置为:http://my-ghost-blog.comGhost默认端口为2366,打开浏览器访问http://192.168.2.178:2366即可看到界面:登录后台访问http://192.168。2.178:2366/admin地址:Ghost是一个独立的程序,可以直接在nodejs环境下运行。在config.js文件中,将Ghost的监听端口2366修改为80。但是在生产环境中,我们一般都会在前端添加Nginx。安装和配置Nginx:#apt-getinstallnginx#rm/etc/nginx/sites-enabled/default#vi/etc/nginx/sites-available/ghostserver{listen0.0.0.0:80;服务器名称vpsee.com;访问日志/var/log/nginx/vpsee.com.log;location/{proxy_set_headerX-Real-IP$remote_addr;proxy_set_headerHOST$http_host;proxy_set_headerX-NginX-Proxytrue;proxy_passhttp://127.0.0.1:2368;proxy_redirect关闭;}}#ln-s/etc/nginx/sites-available/ghost/etc/nginx/sites-enabled/ghost#/etc/init.d/nginxrestartNginx收到请求后会传给(proxy_pass)Ghost服务程序在这次最好把刚才测试用的Ghost配置修改恢复为'127.0.0.1',修改后记得重启Ghost:#viconfig.js...//Hosttobepassedtonode's`net.Server#listen()`host:'127.0.0.1',...每次npmstart太麻烦了,为了让Ghost程序在系统启动后自动运行,需要在Upstart中添加脚本:#vi/etc/init/ghost.confstartonstartupscriptcd/root/ghostnpmstartendscript以后需要启动、重启或停止Ghost,可以使用serviceghoststart/restart/stop:#serviceghostrestartghoststop/waitingghoststart/running,process11619comparedtoWordPress'臃肿的Ghost轻巧得多通过Markdown格式,Node.js实时和漂亮的界面,Ghost为用户提供了一种更简单、更纯粹的编写和发布内容的方式。左边是编辑后的文章,右边是实时预览: