JustYeh的前端博客

Ghost博客在windows下的搭建过程

2019-07-02

Ghost博客

今晚通宵加班,干点私活,把自己的个人博客搭好了,写一下过程,大家可以参考一下! 过程比较新手向,所以可能比较啰嗦,请大家不要介意!

域名

万网买的不多说,https://wanwang.aliyun.com/

主机

vultr服务器,选了乞丐版(土豪随意),37一个月,速度还可以,顺便可以搭个VPN,美滋滋,感兴趣的可以参考这个链接

关于Ghost

基于 Node.js 的开源博客平台,简单易用,支持MarkDown语法+在线预览,更多细节请移步Ghost中文网

以上都是废话,干货在下面

环境

由于当时在Linux上搭建VPN一直不成功,所以就转投到了Windows Server,所以以下的所有操作都是基于Windows平台下的

安装Node.js

Ghost将Node.js v4 LTS 成为 Ghost 推荐版本,所以下载的是 4.2.0 版本,安装很简单,直接下一步就好

安装Ghost

推荐在Ghost中文网下载中文集成版本,此版本已经集成好了node_modules,省却了许多麻烦

  • 打开node控制台,进入到ghost所在目录 cd Downloads/ghost-#.#.#
  • 在命令行中执行 npm install --production 命令,这一步时最好打个梯子,有时npm会出现下载不完全的问题,各种坑
  • 当 npm 安装成功后,输入 npm start 启动开发模式下的 Ghost
  • 在浏览器中,访问 127.0.0.1:2368 即可查看最新搭建的 Ghost 博客
Ghost的配置

这里面,邮件的配置比较麻烦,我也是在网上找的,我使用的是163邮箱,如果你使用的是其他产品,就需要自行搜索配置方法了,以下是我的配置文件:

var path = require('path'),
    config;
config = {
    // ### Production
    production: {
        url: 'http://justyeh.com',
        mail: {
            transport: 'SMTP',
            options: {
                service: 'Mailgun',
                port: 25,
                host: 'smtp.163.com',
                auth: {
                    user: '[email protected]', // 邮件账户
                    pass: '******'  // 邮件密码
                }
            }
        },
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            },
            debug: false
        },

        // 配置MySQL 数据库
        /*database: {
            client: 'mysql',
            connection: {
                host     : 'host',
                user     : 'user',
                password : 'password',
                database : 'database',
                charset  : 'utf8'
            },
            debug: false
        },*/
        server: {
            host: '127.0.0.1',
            port: '2368'
        },
        //Storage.Now,we can support `qiniu`,`upyun`, `aliyun oss`, `aliyun ace-storage` and `local-file-store`
        storage: {
            provider: 'local-file-store'
        }
    },

    // ### Development **(default)**
    development: {
        // The url to use when providing links to the site, E.g. in RSS and email.
        // Change this to your Ghost blog's published URL.
        url: 'http://localhost:2368',
        // #### Database
        // Ghost supports sqlite3 (default), MySQL & PostgreSQL
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost-dev.db')
            },
            debug: false
        },
        // #### Server
        // Can be host & port (default), or socket
        server: {
            // Host to be passed to node's `net.Server#listen()`
            host: '127.0.0.1',
            // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
            port: '2368'
        },
        // #### Paths
        // Specify where your content directory lives
        paths: {
            contentPath: path.join(__dirname, '/content/')
        }
    },

    // **Developers only need to edit below here**
    // ### Testing
    // Used when developing Ghost to run tests and check the health of Ghost
    // Uses a different port number
    testing: {
        url: 'http://127.0.0.1:2369',
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost-test.db')
            }
        },
        server: {
            host: '127.0.0.1',
            port: '2369'
        },
        logging: false
    },

    // ### Testing MySQL
    // Used by Travis - Automated testing run through GitHub
    'testing-mysql': {
        url: 'http://127.0.0.1:2369',
        database: {
            client: 'mysql',
            connection: {
                host: '127.0.0.1',
                user: 'root',
                password: '',
                database: 'ghost_testing',
                charset: 'utf8'
            }
        },
        server: {
            host: '127.0.0.1',
            port: '2369'
        },
        logging: false
    },

    // ### Testing pg
    // Used by Travis - Automated testing run through GitHub
    'testing-pg': {
        url: 'http://127.0.0.1:2369',
        database: {
            client: 'pg',
            connection: {
                host: '127.0.0.1',
                user: 'postgres',
                password: '',
                database: 'ghost_testing',
                charset: 'utf8'
            }
        },
        server: {
            host: '127.0.0.1',
            port: '2369'
        },
        logging: false
    }
};
module.exports = config;
安装Nginx

我使用的是1.8.1版本,解压后修改配置文件

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
listen 80;
server_name justyeh.com www.justyeh.com;
location / {
proxy_set_header   X-Real-IP $remote_addr;
proxy_set_header   Host      $http_host;
proxy_pass         http://127.0.0.1:2368;
}
}
}

稍微解释一下,listen 代表监听80端口,server_name 是你的网站,proxy_pass 代表转发,将 justyeh.com 的请求转发到 http://127.0.0.1:2368

之后右键 nginx.exe 以管理员身份运行nginx程序便可启动服务器

解析

这个没什么好说的,百度一下应该就有了,在阿里云解析上也有教程! 如果前面的步骤都没有出问题,解析完成之后就可以通过你的域名访问你的博客网站了。至此,大功告成!