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

系统 Linux
Ghost 是一款开源的博客平台,网上的开源博客程序众多,去年刚上线的 Ghost 来势汹汹正迅速捕获用户,0.4.1 这么早期的版本就让 Coding Horror 拥抱了 Ghost。本文分享了在 Ubuntu 上搭建 Ghost 博客平台的方法。

Ghost 是一款开源的博客平台,基于 Node.js,由前 WordPress UI 主管 John O’Nolan 和 WordPress 开发人员 Hannah Wolfe 创立。网上的开源博客程序众多,去年刚上线的 Ghost 来势汹汹正迅速捕获用户,0.4.1 这么早期的版本就让 Coding Horror 拥抱了 Ghost。Ghost 主题/模版越来越多,一些优秀的 WordPress 主题商,比如 WooThemes 都开始提供 Ghost 主题了

安装 Ghost 非常容易,甚至比 WordPress 还简单。下面的安装步骤在 Ubuntu 12.04.4 LTS Server 版本上测试通过。

切换到 root 账号升级和更新整个系统:

$ sudo -i

# apt-get update
# apt-get upgrade

安装 Node.js 运行环境:

# apt-get install g++ make python python-software-properties
# add-apt-repository ppa:chris-lea/node.js
# apt-get update
# apt-get install nodejs

下载、解压 Ghost 后安装:

# cd
# wget https://ghost.org/zip/ghost-0.4.1.zip
# unzip ghost-0.4.1.zip -d ghost
# cd ghost
# npm install --production

配置 Ghost 使其监听本机上的所有 IP,修改 ’127.0.0.1′ 为 ’0.0.0.0′:

# vi config.js
...
       server: {
            // Host to be passed to node's `net.Server#listen()`
            host: '0.0.0.0',
            // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
            port: '2368'
        }
...

使用 npm 启动 Ghost 程序:

# npm start

> ghost@0.4.1 start /root/ghost
> node index

Ghost is running in development...
Listening on 0.0.0.0:2368
Url configured as: http://my-ghost-blog.com

Ghost 的默认端口是 2366,打开浏览器访问 http://192.168.2.178:2366 就可以看到界面了:

Ghost

 

登录后台访问 http://192.168.2.178:2366/admin 地址:

Ghost

 

Ghost 是独立程序,在 nodejs 环境下可以直接运行,在 config.js 文件里修改 Ghost 的监听端口 2366 为 80 就可以了,不过在生产环境我们一般在前端加个 Nginx.

安装和配置 Nginx:

# apt-get install nginx
# rm /etc/nginx/sites-enabled/default

# vi /etc/nginx/sites-available/ghost
server {
    listen 0.0.0.0:80;
    server_name vpsee.com;
    access_log /var/log/nginx/vpsee.com.log;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://127.0.0.1:2368;
        proxy_redirect off;
    }
}

# ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ghost

# /etc/init.d/nginx restart

Nginx 接到请求后会 pass 给(proxy_pass)Ghost 服务程序,这时候最好把刚才测试用的 Ghost 配置修改还原成 ’127.0.0.1′,修改后记得重启 Ghost:

# vi config.js
...
            // Host to be passed to node's `net.Server#listen()`
            host: '127.0.0.1',
...

每次 npm start 太麻烦,为了 Ghost 程序在系统启动后能自动运行,需要加入脚本到 Upstart 里:

# vi /etc/init/ghost.conf
start on startup

script
    cd /root/ghost
    npm start
end script

以后需要启动、重启或者停止 Ghost 就可以用 service ghost start/restart/stop 了:

# service ghost restart
ghost stop/waiting
ghost start/running, process 11619

相比 WordPress 的臃肿 Ghost 要轻爽得多。通过 Markdown 格式、Node.js 的实时和漂亮的界面,Ghost 给用户提供了一种更简单、更纯粹的内容写作发布方式。左边是编辑文章,右边是实时预览:

Ghost

责任编辑:黄丹 来源: vpsee.com
相关推荐

2016-07-26 13:58:52

Ubuntulinux网桥

2019-08-02 15:30:42

UbuntuMongoDB命令

2019-08-30 11:20:28

UbuntuVirtualBoxLinux

2018-10-15 15:23:50

UbuntupipPython

2024-01-04 11:50:00

UbuntuDocker

2023-08-08 12:38:52

2015-10-16 10:07:22

Justniffer安装Ubuntu

2014-06-30 09:27:17

UbuntuTomcat集群

2013-07-25 10:00:30

UbuntuVirtualBox

2017-03-29 16:18:11

LinuxUbuntuRedmine

2015-08-04 14:04:28

UbuntuPDF文件

2021-09-11 15:41:55

UbuntuDropbox云服务

2019-08-13 16:10:38

UbuntuLinux时间同步

2021-07-12 14:47:16

UbuntuZlib代码

2017-08-02 15:15:55

UbuntuNoSQLOrientDB

2019-10-21 13:28:38

UbuntuPostgreSQL命令

2016-11-03 20:06:53

UbuntuGrafanaDocker

2019-05-09 09:00:00

WindowsKafka

2018-05-25 11:55:41

2016-01-15 09:56:44

LinuxUbuntuGlances
点赞
收藏

51CTO技术栈公众号