成功在BAE上部署ghost 5.0
这周摸索着网站的建设,终于在今天成功上线!这里要谢谢ghost中文网和群里的网友,他的博客在这opengiser。他们的帮助太重要了。现在把过程记录下来,共同学习。试运营地址在edwardesire。 现在放ACE上了
- 下载安装包
总共需要下载2个东西。
新建BAE工程
在百度开发云平台的管理控制台下一次点击:开发者服务管理->创建工程->创建->应用引擎-添加部署-创建。这样nodejs的环境就建好了。这里一起把数据库也建立起来。这里我使用的是mysql,点击应用引擎中的扩展服务即可,添加新服务当然使用免费版的咯。配置
接下来就是在本地把源码配置好咯。将工程clone下来后,用ghost源码覆盖掉。在本地运行命令npm install,后将下载好的mysql覆盖掉node_modules下原有的。然后打开根目录的config.example.js将database段修改为如下:production: {
database: {
client: 'mysql',
connection: {
host: 'sqld.duapp.com',
port: 4050,
user: '#####', //你的ak
password: '#####', //你的sk
database: '#####',//数据库名
charset: 'utf8'
},
debug: false
},
server: {
host: '127.0.0.1',
port: '18080'
}
}
最后再修改根目录的config.example.js。修改启动命令,将"start": "node index"改为"start": "node index.js"。并去掉依赖dependencies、optionalDependencies、devDependencies这三项。
修改5.0中与BAE不兼容的部分
按照q友悟道所说需要注释掉core/server/index.js中305行的ghostStartMessages()。原因是这个方法的内部与BAE不兼容。图像存储问题
在package.json中的dependencies添加七牛的依赖包,在config.example.js中production和添加:qiniu: {
bucketname: '#####', //七牛云的目录名
ACCESS_KEY: '#####', //七牛云的ak
SECRET_KEY: '#####', //七牛云的sk
root: '/image/',
prefix: 'http://' //七牛的空间域名
}
最后在core/server/storage做两个操作
+ 覆盖index.js文件
var errors = require('../errors'),
storage;
var qiniuConfig = require('../config/').qiniu;
function get_storage() {
// TODO: this is where the check for storage apps should go
// Local file system is the default
var storageChoice = qiniuConfig? 'qiniu':'localfilesystem';
if (storage) {
return storage;
}
try {
// TODO: determine if storage has all the necessary methods
storage = require('./' + storageChoice);
} catch (e) {
errors.logError(e);
}
return storage;
}
module.exports.get_storage = get_storage;
+ 并添加一个qiniu.js文件
// # Local File System Image Storage module
// The (default) module for storing images, using the local file system
var _ = require('lodash'),
express = require('express'),
fs = require('fs-extra'),
nodefn = require('when/node/function'),
path = require('path'),
when = require('when'),
config = require('../config'),
errors = require('../errors'),
baseStore = require('./base'),
crypto = require('crypto'),
qiniu = require('qiniu'),
qiniuConfig = config.qiniu,
qiniuStore;
qiniu.conf.ACCESS_KEY = qiniuConfig.ACCESS_KEY;
qiniu.conf.SECRET_KEY = qiniuConfig.SECRET_KEY;
qiniu.conf.USER_AGENT = 'Ghost 0.4.2';
var putPolicy = new qiniu.rs.PutPolicy(qiniuConfig.bucketname),
uptoken = putPolicy.token();
qiniuStore = _.extend(baseStore, {
// ### Save
// Saves the image to storage (the file system)
// - image is the express image object
// - returns a promise which ultimately returns the full url to the uploaded image
'save': function (image) {
var saved = when.defer(),
md5sum = crypto.createHash('md5'),
ext = path.extname(image.name),
targetDirRoot = qiniuConfig.root,
targetFilename,
key,
extra = new qiniu.io.PutExtra();
var savedpath = path.join(config.paths.imagesPath, image.name);
nodefn.call(fs.copy, image.path, savedpath).then(function(){
return nodefn.call(fs.readFile, savedpath);
}).then(function(data) {
md5 = md5sum.update(data).digest('hex');
targetFilename = path.join(targetDirRoot, md5.replace(/^(\w{1})(\w{2})(\w+)$/, '$1/$2/$3')) + ext;
targetFilename = targetFilename.replace(/\\/g, '/');
key = targetFilename.replace(/^\//, '');
return nodefn.call(qiniu.io.put, uptoken, key, data, extra);
}).then(function () {
return nodefn.call(fs.unlink, savedpath).then(function(){
return nodefn.call(fs.unlink, image.path);
}).otherwise(errors.logError);
}).then(function () {
// prefix + targetFilename
var fullUrl = qiniuConfig.prefix + targetFilename;
return saved.resolve(fullUrl);
}).otherwise(function (e) {
errors.logError(e);
return saved.reject(e);
});
return saved.promise;
},
'exists': function (filename) {
// fs.exists does not play nicely with nodefn because the callback doesn't have an error argument
var done = when.defer();
fs.exists(filename, function (exists) {
done.resolve(exists);
});
return done.promise;
},
// middleware for serving the files
'serve': function () {
var ONE_HOUR_MS = 60 * 60 * 1000,
ONE_YEAR_MS = 365 * 24 * ONE_HOUR_MS;
// For some reason send divides the max age number by 1000
return express['static'](config.paths.imagesPath, {maxAge: ONE_YEAR_MS});
}
});
module.exports = qiniuStore;
最后注释掉fonts.googleapis相关的字体加载,就可以上传代码、发布咯。
- Next
个人觉得需要文章分类、归档archive和评论区,接下来就是搞定他们了。
!参考学习
成功在BAE上部署ghost 5.0的更多相关文章
- BAE上部署Ghost 0.5.1注意事项
BAE上部署Ghost可参考基本安装上述安装使用的是ghost0.4.7版本 在ghost 0.5 中为了解决测试时事件侦听器过多引发的警告,在注册single事件时,将代码由原先的 process. ...
- 在CentOS 7上部署Ghost博客
作者:waringid 一.简介 跟静态博客不同的是,Ghost 这种轻量级的动态博客,有一个管理后台,可以直接写作和管理博客.本质上,跟 WordPress 是相通的,只是 Ghost 搭建在 No ...
- 在BAE上部署Pomelo
BAE升级到3.0后顿时感觉好用了很多,俨然云主机的感觉. 底下我将分享我在BAE上部署Pomelo的过程. 首先需要拥有一个BAE的执行单元.没有的可以自行百度并部署. 接着svn得出代码到本地.此 ...
- 关于在BAE上部署ThinkPHP框架的问题
现在有点小兴奋,因为在在BAE上部署ThinkPHP框架的问题快折腾一天了,午觉都没睡,不过没白整总算有点结果.不扯淡了,直入正题吧. 之前熟悉ThinkPHP框架,想在BAE上用ThinkPHP做点 ...
- Coding上部署Ghost博客
Ghost构建于Node.js平台之上.支持0.10.*版本号的Node.js. 在你的本地计算机上执行Ghost事实上非常easy,前提是你已经安装了Node.js. 什么是Node.js? 略过 ...
- 那些在BAE上部署node.js碰到的坑
在BAE上使用node.js半年多了,其中碰到了不少因为BAE云环境限制碰到的坑 写下来大家碰到了,也不用那么麻烦的去看好几天代码了,直接对症下药 官方公布的坑有: BAE是使用package.jso ...
- IIS 6.0上部署.NET 4.0网站
最近需要把VS2010开发的网站部署到Windows Server 2003的服务器上去, Windows Server 2003操作系统自带的为IIS 6.0,IIS 6.0一般只支持.NET 2. ...
- 在CentOS上部署kubernetes1.9.0集群
原文链接: https://jimmysong.io/kubernetes-handbook/cloud-native/play-with-kubernetes.html (在CentOS上部署kub ...
- Ubuntu上部署Ghost博客
所有文章搬运自我的个人主页:sheilasun.me 刚刚成功把自己的ghost博客部署到Linode VPS上了,在这里回顾并顺便整理一下从购买域名到部署代码到服务器的整个过程. 购买域名 万网或者 ...
随机推荐
- 【NGUI】屏幕自适应(不用UIStretch,用UIRoot)---------------good
原地址:http://blog.csdn.net/lzhq1982/article/details/18814023 这篇文章是转载的,之前用UIStretch做屏幕自适应,但一直有两个硬伤让我难受, ...
- grep正则表达式后面的单引号和双引号的区别
单引号''是全引用,被单引号括起的内容不管是常量还是变量者不会发生替换:双引号""是部分引用,被双引号括起的内容常量还是常量,变量则会发生替换,替换成变量内容! 一般常量用单引号' ...
- ***CI异常记录到日志:CodeIgniter中设计一个全局exception hook
在CodeIgniter中,当发生异常时,经常要通知系统管理员,因此有必要在全局的高度上 捕捉异常,因此可以写一个hook, 比如在config目录的hook.php中,加入: $hook['pre_ ...
- strip_tags() 函数剥去 HTML、XML 以及 PHP 的标签
定义和用法 strip_tags() 函数剥去 HTML.XML 以及 PHP 的标签. 语法 strip_tags(string,allow) 参数 描述 string 必需.规定要检查的字符串. ...
- mac 用 brew
mac 下用 brew 安装插件, 有重复的不会再次安装,比xmap模式好
- boost在linux下的编译和使用
上一篇boost在windows可以正常的使用了,但是在linux下不行. [尝试一:使用和windows同一套代码编译,编译时报错] 我是在Ubuntu使用共享文件夹的方式和windows使用的同一 ...
- SQLite入门与分析(四)---Page Cache之事务处理(2)
写在前面:个人认为pager层是SQLite实现最为核心的模块,它具有四大功能:I/O,页面缓存,并发控制和日志恢复.而这些功能不仅是上层Btree的基础,而且对系统的性能和健壮性有关至关重要的影响. ...
- http_build_query函数(学习)
http_build_query函数 http_build_query -- 生成 url-encoded 之后的请求字符串 描述 string http_build_query ( array ...
- Oracle命令(一):Oracle登录命令
1.运行SQLPLUS工具 C:\Users\wd-pc>sqlplus 2.直接进入SQLPLUS命令提示符 C:\Users\wd-pc>sqlplus /nolog 3.以OS身份连 ...
- Visual C#每一次新版本的变化
What's New in Visual C# .NET 2003[Visual Studio .NET 2003] What's New in Visual C# 2005 What's New i ...