
一、环境准备
在开始安装Ghost之前,您需要确保您的服务器满足以下条件:
1. Node.js (推荐使用LTS版本)
2. npm (Node.js的包管理器)
3. MySQL 或 PostgreSQL 数据库(可选)
4. 静态文件服务器,如Nginx或Apache
二、下载和安装Ghost
1. 使用Git克隆Ghost的仓库到您的服务器:
```bash
git clone https://github.com/TryGhost/Ghost.git ghost
```
2. 进入Ghost目录,并安装所需的依赖:
```bash
cd ghost
npm install
```
3. 初始化Ghost配置文件:
```bash
npm run init
```
三、配置数据库
1. 如果您选择使用MySQL或PostgreSQL,需要创建数据库并配置数据库连接信息。在Ghost的配置文件中(config.js),找到数据库配置部分并修改:
```javascript
database: {
client: 'mysql',
connection: {
host: '127.0.0.1',
user: 'your_database_user',
password: 'your_database_password',
database: 'your_database_name'
}
}
```
2. 保存配置文件后,运行以下命令以启动Ghost:
```bash
npm start
```
四、配置静态文件服务器
1. 为了使Ghost能够在生产环境中运行,您需要配置Nginx或Apache来处理静态文件。以下是一个Nginx配置示例:
```nginx
server {
listen 80;
server_name your_blog_domain.com;
location / {
proxy_pass http://localhost:2368;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
```
2. 重新加载Nginx配置并启动服务:
```bash
sudo systemctl reload nginx
```
五、设置反向代理和SSL
1. 为了提高安全性,建议使用SSL证书。您可以使用Let's Encrypt免费获取证书。配置Nginx以使用SSL并设置反向代理:
```nginx
server {
listen 443 ssl;
server_name your_blog_domain.com;
ssl_certificate /etc/letsencrypt/live/your_blog_domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your_blog_domain.com/privkey.pem;
location / {
proxy_pass http://localhost:2368;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
}
}
```
2. 重启Nginx以应用SSL配置:
```bash
sudo systemctl restart nginx
```
评论列表