【Ghost系列-1】在OpenShift上免费搭建Ghost博
初次接触Ghost的时候,看到大家都是在Nitrous.io上来玩的,于是也尝试了一下,跟着网上的教程一步一步搭起来了。不过它每隔一段时间就会自动关机,而且每月提供的免费时长也很有限,所以我尝试着换一个Pass平台可以让Ghost一直稳定地运行起来。
玩过Ghost的人都知道,它是构建在Node.js平台之上,所以我们只需要找到支持Node.js的主机就行了,在Google上搜了一下,有人已经把所有支持Node.js的主机都列出来了,地址:https://github.com/nodejs/node-v0.x-archive/wiki/Node-Hosting
对比了一下,最后我选择了OpenShift,主要是因为它免费,而且它的应用里面已经自带了Ghost0.7.5的版本。好了,说了这么多,下面开始搭建我们的Ghost博客了。
1.在OpenShift上建立Ghost应用
首先,我们需要一个OpenShift账号,注册什么的就没什么好说的了,不过有一点还是要提醒一下大家,注册的时候验证码好像被墙了,可以看下面的两张图,有验证码的是我用VPN访问的。这里大家注意一下就好了。


注册成功的界面

然后我们创建一个Ghost应用

进去之后直接创建应用就行了,感觉没什么可以修改的,这样就创建好了一个Ghost博客,下面是我创建的两个应用

2.OpenShift空间绑定域名
进入你的应用之后,默认的地址应该是打不开的,点旁边的change按钮绑定你自己的域名

添加你自己的域名,点击保存即可。

在你的域名提供商那里进行域名解析,我用的是花生壳。在你的域名管理处添加CHAME记录

好了,现在访问www.maplejoyous.cn就可以访问我刚建的Ghost博客了,想要编辑的话可以在后面加/ghost,即可进入后台。结果发现Ghost的默认网址还是OpenShift分配的网址,后台操作不了。我们得修改应用里面的地址。

3.使用SSH管理OpenShift应用
OpenShift强大之处是可以用SSH来直接管理,像操作VPS主机一样来执行相关命令
首先,我们下载一个Puttygen用来生成密钥,点击Generate来生成,记住要在窗口里不断地移动你的鼠标

复制生成的公钥

将该公钥内容粘贴到OpenShift空间的Public key中,为你的key取个名字

好了,Seeting里面出现了你刚才添加的key信息

然后,我们转到Puttygen里面,点击Conversions导出我们的私钥,导出后记得妥善保管,这是SSH连接OpenShift的凭证。

接下来就是连接到你的OpenShift空间了,选择一款SSH软件,如xshell、SecureCRT。我用的是xshell,找到你应用里面的Source Code,里面包含你的主机名和用户名。

打开xShell,新建会话,填好属性

点击确定后,开始连接,接着输入你的用户名,即Source Code里面ssh://和@中间的这部分字符串。

选择Public Key,用户密钥选择你刚才导出的私钥文件

连接OpenShift空间成功,接下来我们就可以像操作VPS一样的来进行操作了

我们敲一下命令试一下,比如:ls -l,可以看到列出来的文件名

4.修改Ghost域名
在xShell里面进行操作,先进入Ghost的博客目录
cd app-root/repo
编辑config.js
vim config.js
按下i
键,进入编辑模式,将+process.env.OPENSHIFT_APP_DNS
地方的url都修改为你的域名,即http://maplejoyous.cn
,按下Esc退出编辑模式,输入:wq
保存一下
退出vim后使用ctl_all restart
来重启你的应用,等出现Starting NodeJS cartridge
后,就可以关闭SSH了。Ok,大功告成,现在就可以进入后台了http://www.maplejoyous.cn/ghost/,注册一个账号后就可以编辑你的文章了
参考资料
1.新版OpenShift空间申请使用教程:安装WP、域名绑定等
2.在Openshift上免费架设Ghost博客并绑定域名、安装主题