Ubuntu 14.04 安装 Node.js 和 Ghost 博客程序

5,490次阅读
没有评论

Ubuntu 14.04 安装 Node.js 和 Ghost 博客程序

Ghost 是基于 Node.js 的开源博客平台,由前 WordPress UI 部门主管 John O’Nolan 和 WordPress 高级工程师(女)Hannah Wolfe 创立,目的是为了给用户提供一种更加纯粹的内容写作与发布平台。

Ghost 将拥有如下主要特性:

通过直接显示多重信息的控制台。你可以查看网站的页面访问量,社交媒体的大致状况,还可以知道哪篇文章更受欢迎。你还可以运用小挂件(widget),让控制台显示更多其页面它相关的信息。

文章管理页面变为两栏布局。左侧为文章列表,显示文章标题,以及每篇文章的点击量,分类,标签等等;右侧则直接预览文章内容。不像现在,要进入“编辑”页面,才能看到文章内容,十分麻烦

完全支持 MarkDown 语法写作。文章撰写页面也变成两栏布局,左边显示以 MarkDown 语法写作的原稿,右边则显示将原稿转换成网页格式的样子。MarkDown 是什么?它是一个标记语言,能够将相应的文本段标记出来,在转换成网页的时候,能够转换成相对应的效果。好处是,当你想给字体加粗或倾斜的时候,手不必离开键盘,直接输入星号就可以了,比如“**加粗 **”、“* 倾斜*”。

除了以上三大特性以外,Ghost 其它设计主要以“简化”为目标,比如说它不打算为用户提供过多选项,不支持原生的评论系统,不希望兼容已经几年没有更新的插件。当然,这样的设计也无从评论是好是坏,有人赞同则必有人反对。

Ghost 是一个用 Nodejs 写成的博客程序。官方网站是http://www.ghost.org/,官方中文文档链接是http://docs.ghost.org/zh/installation/

这里我们介绍下在 Ubuntu 14.04 LTS 安装 Node.js 和 Ghost 的方法。

一、安装 Node.js

为了保持最新版本,我们采用 PPA 形式,可以直接用这个脚本导入 PPA:

sudo curl -sL https://deb.nodesource.com/setup | sudo bash -

导入完毕以后,直接安装 Node.js

sudo apt-get install nodejs

这个 Node.js 的包已经包含了 npm 所以你不用单独安装 npm,而有些 Node.js 程序还得单独安装 build-essentials 包,你也可以安装一下:

sudo apt-get install build-essential

安装完毕以后查看一下 Node.js 和 npm 的版本

root@example:~# node -v
v0.10.33
root@example:~# npm -v
1.4.28

Ghost 需要运行在 0.10.* 的 Node.js 版本,请注意。

二、下载 Ghost 程序

基于安全考虑,可以新建立个 ghost 用户,这里我们安装在 /var/www/ 目录下

useradd ghost
mkdir /var/www
cd /var/www
curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip
unzip ghost.zip
chown -R ghost:ghost /var/www

这样就设置好权限并下载好 Ghost 了

三、安装配置 Ghost

首先用 npm 安装 npm install --production 注意有两个减号 npm 安装结束后,可以输入这个命令让 Ghost 以开发者模式启动 npm start 然后就可以本机从 http://127.0.0.1:2368/ 查看搭建好的 Ghost 博客了,由于我们是安装在服务器端,所以你本地浏览器是无法访问的,先按 Ctrl + C 停止一下,这时候就会生成一个 config.js,然后修改 config.jsurl: 'http://my-ghost-blog.com', 这行改成你的域名,比如 url: 'http://example.com', 安装结束,然后我们需要让 Ghost 保持后台运行,并配置 Nginx 反向代理让外网可以访问。

四、让 Ghost 保持后台运行 + 开启启动

这里有两种方式

1、使用 forever 以后台任务运行 Ghost

安装 forever npm install forever -g 运行 Ghost NODE_ENV=production forever start index.js 然后可以通过 forever stop index.js 停止 Ghost 也可以通过 forever list 检查 Ghost 是否运行

2、使用 Supervisor 后台运行 Ghost 并开机启动

安装 Supervisor sudo apt-get install supervisor 创建一个 Ghost 启动脚本文件,如 /etc/supervisor/conf.d/ghost.conf 编辑如下

[program:ghost]
command = node /var/www/index.js
directory = /var/www
user = ghost
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/ghost.log
stderr_logfile = /var/log/supervisor/ghost_err.log
environment = NODE_ENV="production"

重启 Supervisor 即可生效

service supervisor restart

也可以使用 Supervisor 启动 Ghost

supervisorctl start ghost

然后我们开始安装 Nginx 配置反向代理让你本地可以访问。

四、安装 Nginx 配置反向代理

首先安装 Nginx

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx-extras

修改 /etc/nginx/sites-available/default

server {
    listen	80;
    server_name example.com;

    location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:2368;
    }

    location ~* \.(?:ico|css|js|gif|jpe?g|png|ttf|woff)$ {
        access_log off;
        expires 30d;
        add_header Pragma public;
        add_header Cache-Control "public, mustrevalidate, proxy-revalidate";
        proxy_pass http://127.0.0.1:2368;
    }

    location = /robots.txt {access_log off; log_not_found off;}
    location = /favicon.ico {access_log off; log_not_found off;}

    location ~ /\.ht {deny all;}
}

保存并重启 Nginx

sudo service nginx restart

五、本地浏览器访问 Ghost

然后你就可以在本地用 http://example.com/ 访问刚才搭建好的 Ghost 了,如图:

Ubuntu 14.04 安装 Node.js 和 Ghost 博客程序

进入 http://example.com/ghost/setup/开始创建第一个用户,即管理员帐号,接下来开始你的博客之旅吧!如图:

Ubuntu 14.04 安装 Node.js 和 Ghost 博客程序

Ubuntu 14.04 安装 Node.js 和 Ghost 博客程序

正文完
 
VPSWe
版权声明:本站原创文章,由 VPSWe 2015-01-24发表,共计3072字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码