Debian 8.x / Ubuntu 16.04.x 搭建 Ghost 博客教程
Ghost 是一個專為寫作而設計的開源博客平台,因其簡潔的界面和強大的功能而受到廣泛歡迎。本文將指導您如何在 Debian 8.x 或 Ubuntu 16.04.x 系統上搭建 Ghost 博客,讓您能夠輕鬆開始您的寫作之旅。
前期準備
在開始之前,您需要確保您的伺服器上已安裝以下軟件:
- Node.js(版本 14.x 或更高)
- npm(Node.js 的包管理器)
- MySQL 或 SQLite(作為數據庫)
- Git(可選,用於版本控制)
您可以使用以下命令來安裝這些依賴項:
sudo apt update
sudo apt install nodejs npm mysql-server git安裝 Node.js
首先,您需要安裝 Node.js。可以使用 NodeSource 提供的安裝腳本來安裝最新版本的 Node.js:
curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt install -y nodejs安裝完成後,您可以使用以下命令檢查 Node.js 和 npm 的版本:
node -v
npm -v安裝 Ghost
接下來,您可以使用 npm 安裝 Ghost。首先,創建一個新的目錄來存放 Ghost:
mkdir -p ~/ghost
cd ~/ghost然後,使用 npm 安裝 Ghost:
npm install ghost配置 Ghost
安裝完成後,您需要配置 Ghost。首先,您需要創建一個配置文件:
cp config.example.json config.json然後,使用文本編輯器打開 config.json 文件,根據您的需求進行修改。特別是,您需要設置您的網站 URL 和數據庫配置。
設置數據庫
如果您選擇使用 MySQL,您需要創建一個數據庫和用戶。可以使用以下命令進入 MySQL:
mysql -u root -p然後,創建數據庫和用戶:
CREATE DATABASE ghost_db;
CREATE USER 'ghost_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON ghost_db.* TO 'ghost_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;在 config.json 中,將數據庫配置更改為:
"database": {
"client": "mysql",
"connection": {
"host": "127.0.0.1",
"user": "ghost_user",
"password": "your_password",
"database": "ghost_db"
}
}啟動 Ghost
配置完成後,您可以啟動 Ghost。使用以下命令啟動 Ghost:
npm start如果一切正常,您應該能夠在瀏覽器中訪問您的 Ghost 博客,網址為 http://your_server_ip:2368。
設置反向代理(可選)
如果您希望通過標準的 HTTP 端口(80)訪問您的博客,您可以設置 Nginx 作為反向代理。首先,安裝 Nginx:
sudo apt install nginx然後,創建一個新的 Nginx 配置文件:
sudo nano /etc/nginx/sites-available/ghost在文件中添加以下內容:
server {
listen 80;
server_name your_domain.com;
location / {
proxy_pass http://127.0.0.1:2368;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}保存並退出後,啟用配置並重啟 Nginx:
sudo ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/
sudo systemctl restart nginx總結
通過以上步驟,您已成功在 Debian 8.x 或 Ubuntu 16.04.x 系統上搭建了 Ghost 博客。這是一個強大且靈活的寫作平台,適合各種需求。如果您需要穩定的伺服器來運行您的博客,考慮使用 香港VPS 服務,提供高效能和可靠性,讓您的網站運行無憂。