mx space
是一個簡潔而不簡單的個人博客系統,它夠快,夠現代。你可以利用它構建一個屬於自己的個人空間,記錄生活,分享知識。mx Space 核心服務;基於 nestjs (nodejs),需安裝 mongoDB 和 Redis 方可完整運行
shiro
是基於 mx space 使用 react 開發的主題系統
以上系統在 github 均有數千 star, 比較成熟的同時有很多有趣的功能,所以本次博客重建直接使用這一套系統
準備工作#
- 伺服器一台,非 windows 即可
- 域名一個,需 HTTPS
首先我們去購買一台伺服器,任意配置即可,可以去找一些新客優惠,幾十塊錢一年的那種就可以了,這裡我選擇購買了騰訊雲伺服器,新客 79 一年 配置是 2h2g 寶塔 linux 面板
伺服器購買完成後,我們在寶塔 linux 面板中重裝系統,伺服器默認系統為騰訊雲 os, 這裡從面板安裝 dockerCE, 會自動配置好騰訊雲鏡像
也可以手動安裝 docker 並設置鏡像為阿里雲
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
執行後查看是否成功
docker -v
docker compose version
至此,伺服器準備工作完成
後端 mx space 部署#
配置文件拉取#
在伺服器根目錄進行配置文件拉取
cd && mkdir -p mx-space/core && cd $_
# 拉取 docker-compose.yml 文件
wget https://fastly.jsdelivr.net/gh/mx-space/core@master/docker-compose.yml
配置 Core 啟動配置文件#
將下面配置文件中的值修改為你自己定義的值
- JWT_SECRET = your jwt
- ALLOWED_ORIGINS = your domain
- ENCRYPT_ENABLE = false
- JWT 密鑰:需要填寫長度不小於 16 個字符,不大於 32 個字符的字符串,用於加密用戶的 JWT,務必保存好自己的密鑰,不要洩露給他人。
- 被允許的域名:需要填寫被允許的域名,通常是前端的域名,如果允許多個域名訪問,用英文逗號,分隔。
- 是否開啟加密:如果你確定要開啟加密,將 false 改為 true
啟動 Core#
如果你的伺服器在國內,無法拉取鏡像或拉取速度過慢可自行使用代理或在 docker-compose.yml 裡的 image 前添加鏡像域名,比如 docker.1panel.top/innei/mx-server
docker compose up -d
Nginx 反向代理配置#
安裝 Nginx#
可以使用 docker 安裝,我這裡使用系統安裝
sudo yum install nginx
# 檢查狀態
sudo systemctl status nginx
# 啟動服務
sudo systemctl start nginx
默認使用單域名,即後台管理系統與博客展示系統使用同一域名
另外,不管是前端還是後端的域名,都需要配置好 HTTPS 證書以保證網站能正常訪問
將下面 ssl 證書替換成你自己的
server {
listen 80;
listen 443 ssl http2 ;
## 綁定域名
server_name www.example.com;
index index.html;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
error_log /www/sites/www.example.com/log/error.log;
access_log /www/sites/www.example.com/log/access.log;
location /socket.io {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:2333/socket.io;
}
location /api/v2 {
proxy_pass http://127.0.0.1:2333/api/v2;
}
location /render {
proxy_pass http://127.0.0.1:2333/render;
}
location / {
proxy_pass http://127.0.0.1:2323;
}
location /qaqdmin {
proxy_pass http://127.0.0.1:2333/proxy/qaqdmin;
}
location /proxy {
proxy_pass http://127.0.0.1:2333/proxy;
}
location ~* \/(feed|sitemap|atom.xml) {
proxy_pass http://127.0.0.1:2333/$1;
}
ssl_certificate /www/sites/www.example.com/ssl/fullchain.pem;
ssl_certificate_key /www/sites/www.example.com/ssl/privkey.pem;
ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1;
ssl_ciphers 'your code';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
error_page 497 https://$host$request_uri;
limit_conn perserver 300;
limit_conn perip 25;
limit_rate 512k;
}
反向代理成功後通過綁定域名登錄後台進行初始化
前端 shiro 部署#
確保已安裝 mx Space 後端並且已啟動
配置雲函數#
進入 mx Space 後台,進入「配置與雲函數」頁面,點擊右上角的新增按鈕,在編輯頁面中,填入以下設置:
- 名稱:shiro
- 引用:theme
- 數據類型:JSON
按需修改為你的配置
{
"footer": {
"otherInfo": {
"date": "2020-{{now}}",
"icp": {
"text": "萌 ICP 備 20236136 號",
"link": "https://icp.gov.moe/?keyword=20236136"
}
},
"linkSections": [
{
"name": "關於",
"links": [
{
"name": "關於本站",
"href": "/about-site"
},
{
"name": "關於我",
"href": "/about"
},
{
"name": "關於此項目",
"href": "https://github.com/innei/Shiro",
"external": true
}
]
},
{
"name": "更多",
"links": [
{
"name": "時間線",
"href": "/timeline"
},
{
"name": "友鏈",
"href": "/friends"
},
{
"name": "監控",
"href": "https://status.innei.in/status/main",
"external": true
}
]
},
{
"name": "聯繫",
"links": [
{
"name": "寫留言",
"href": "/message"
},
{
"name": "發郵件",
"href": "mailto:[email protected]",
"external": true
},
{
"name": "GitHub",
"href": "https://github.com/innei",
"external": true
}
]
}
]
},
"config": {
"color": {
"light": [
"#33A6B8",
"#FF6666",
"#26A69A",
"#fb7287",
"#69a6cc",
"#F11A7B",
"#78C1F3",
"#FF6666",
"#7ACDF6"
],
"dark": [
"#F596AA",
"#A0A7D4",
"#ff7b7b",
"#99D8CF",
"#838BC6",
"#FFE5AD",
"#9BE8D8",
"#A1CCD1",
"#EAAEBA"
]
},
"bg": [
"https://github.com/Innei/static/blob/master/images/F0q8mwwaIAEtird.jpeg?raw=true",
"https://github.com/Innei/static/blob/master/images/IMG_2111.jpeg.webp.jpg?raw=true"
],
"custom": {
"css": [],
"styles": [],
"js": [],
"scripts": []
},
"site": {
"favicon": "/innei.svg",
"faviconDark": "/innei-dark.svg"
},
"hero": {
"title": {
"template": [
{
"type": "h1",
"text": "Hi, I'm ",
"class": "font-light text-4xl"
},
{
"type": "h1",
"text": "Innei",
"class": "font-medium mx-2 text-4xl"
},
{
"type": "h1",
"text": "👋。",
"class": "font-light text-4xl"
},
{
"type": "br"
},
{
"type": "h1",
"text": "A NodeJS Full Stack ",
"class": "font-light text-4xl"
},
{
"type": "code",
"text": "<Developer />",
"class": "font-medium mx-2 text-3xl rounded p-1 bg-gray-200 dark:bg-gray-800/0 hover:dark:bg-gray-800/100 bg-opacity-0 hover:bg-opacity-100 transition-background duration-200"
},
{
"type": "span",
"class": "inline-block w-[1px] h-8 -bottom-2 relative bg-gray-800/80 dark:bg-gray-200/80 opacity-0 group-hover:opacity-100 transition-opacity duration-200 group-hover:animation-blink"
}
]
},
"description": "一位獨立開發者用愛編碼。"
},
"module": {
"activity": {
"enable": true,
"endpoint": "/fn/ps/update"
},
"donate": {
"enable": true,
"link": "https://afdian.net/@Innei",
"qrcode": [
"https://cdn.jsdelivr.net/gh/Innei/img-bed@master/20191211132347.png",
"https://cdn.innei.ren/bed/2023/0424213144.png"
]
},
"bilibili": {
"liveId": 1434499
}
}
}
}
預構建運行#
在伺服器中使用 docker 部署
mkdir shiro
cd shiro
wget https://raw.githubusercontent.com/Innei/Shiro/main/docker-compose.yml
wget https://raw.githubusercontent.com/Innei/Shiro/main/.env.template .env
vim .env # 修改你的 ENV 變量
docker compose up -d
docker compose pull # 後續更新鏡像
修改 ENV 變量
# 後端api地址
NEXT_PUBLIC_API_URL=your api
# 後端網關
NEXT_PUBLIC_GATEWAY_URL=your gateway
至此就完成了 mx space + shiro 博客站點的部署,登錄你的域名進行配置之後就可開始寫作啦~
此文由 Mix Space 同步更新至 xLog
原始鏈接為 http://www.sroxck.top/posts/note/record