兩個月前幫我部英國 VPS 續費一年之後,就打算起返個 WordPress 嚟玩下。以下係安裝嘅過程:
事前準備:
- 1. Debian VPS 一部, 要有 Root 權限
- 2. 起 WordPress 用嘅域名, 並且已經指向 VPS 嘅 ip
- 3. DNS 服務商 (Cloudflare)
- 4. SSH 連線工具 (eg: Bitvise)
實際操作
1.安裝必要嘅套件
- 安裝 Docker : 㩒哩度
- 安裝 Nginx 同埋 Certbot
|
1 |
apt-get install nginx certbot |
裝完之後,如果打開 http://<VPS嘅ip> 出現以下畫面,就代表上述嘅套件已經成功安裝

配置 Docker Compose
備註:建議起一個專門 for docker 嘅 directory, 咁樣管理起上嚟會方便啲
1. 輸入 nano docker-compose.yml 建立一個 Docker Compose 嘅配置文件.
2. Copy and Paste 以下內容, 並且按需要修改配置:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
version: "3" services: db: image: mysql:latest volumes: - /docker/db:/var/lib/mysql #可自行修改 restart: always environment: MYSQL_ROOT_PASSWORD: 9HGVye9t2D3OgQhZ85c78UR #務必修改 MYSQL_DATABASE: wordpress MYSQL_USER: user MYSQL_PASSWORD: 9HGVye9t2D3OgQhZ85c78UR #務必修改 wordpress: depends_on: - db image: wordpress:latest ports: - "5000:80" #可自行修改 volumes: - /docker/wp:/var/www/html #可自行修改 restart: always environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_USER: user WORDPRESS_DB_PASSWORD: 9HGVye9t2D3OgQhZ85c78UR #務必修改 WORDPRESS_DB_NAME: wordpress |
3. 輸入 docker compose up -d 啟動容器
簡單配置 WordPress
打開http://<VPS嘅ip>:5000, 然後按指示操作安裝


跟住到設定, 將 WordPress 位址同埋網站位址更換成你嘅 domain

幫域名申請證書
為咗方便, 哩度就會用 Certbot 嚟申請 SSL 證書, 步驟如下 (詳情請參考 certbot 官方指南) :
喺 ssh 輸入以下指令:
|
1 |
certbot certonly --standalone --preferred-challenges http -d blog.example.com |
Last step: 配置 Nginx 反向代理
哩到嘅關鍵係反向代理嘅設定,其它都同標準嘅 server 設定沒咩差別。我個人會把哩段抽出命名為 reverse.conf 放到 snippets 資料夾入面:
|
1 2 3 4 5 6 |
add_header X-Frame-Options SAMEORIGIN; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_hide_header X-Frame-Options; |
跟住到 sites-enabled 編輯 Nginx 配置文件, 哩度因為懶, 所以會用返 Nginx 官方預設嘅文件:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
server { listen 80; server_name your_site.com; # 用自己嘅域名改返 return 301 https://$host$request_uri; } server { listen 443 ssl; server_name your_site.com; # 用自己嘅域名改返 ssl_certificate /etc/letsencrypt/live/your_site.com/fullchain.pem; # 用自己嘅域名改返 ssl_certificate_key /etc/letsencrypt/live/your_site.com/privkey.pem; # 用自己嘅域名改返 location / { include snippets/reverse.conf; proxy_pass http://localhost:5000; } } |
哩個時候, 如果訪問 https://your_site.com 頁面正常顯示嘅話, 就代表 WordPress 建站成功🎉🎉🎉