banner
jiuyue

jiuyue

JiuYue

Mix-Space Deploys Latest Backend Core

Mix Space is a simple yet sophisticated personal blogging system that is fast and modern. You can use it to build your own personal space to document life and share knowledge.

Backend Core Project#

image

System / Environment Requirements#

  • Linux / MacOS (Recommended Debian 11 / 12) The tutorial uses Debian 11 / 12 as an example
  • Linux kernel > 4.19
  • Docker, Docker-Compose
  • 1Panel + OpenResty (optional)

Necessary Preparations#

  • Domain name: The dual-domain mode used in this article is front-end www.vlo.cc, back-end api.vlo.cc
  • SSL certificate required for front-end and back-end domain names: HTTPS is required for the entire site

1. Install Docker / Docker-Compose#

If the server is abroad and you need to use 1Panel, you can directly run the 1Panel installation script to quickly install 1Panel and Docker / Docker-Compose.

First, install some necessary packages:

apt update
apt upgrade -y
apt install curl vim wget gnupg dpkg apt-transport-https lsb-release ca-certificates

Then add the Docker GPG key and apt source:

curl -sSL https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://download.docker.com/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list

For domestic machines, you can use Tsinghua TUNA's domestic source:

curl -sS https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list

Then update the system and install Docker CE:

apt update
apt install docker-ce docker-ce-cli containerd.io

We can use the latest version of docker-compose directly installed from Docker's official GitHub:

curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-Linux-x86_64 > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

At this point, you can use the docker-compose version command to check if the installation was successful.

2. Deploy Core#

1. Pull Configuration File#

cd /opt && mkdir -p mx-space/core && cd $_
# Pull docker-compose.yml file
wget https://fastly.jsdelivr.net/gh/mx-space/core@master/docker-compose.yml

2. Modify Core Configuration File#

cd /opt/mx-space/core
vim docker-compose.yml

Modify the content corresponding to the environment field, adjust the details to comply with YAML syntax, and save.

Warning

The default MongoDB database and Redis do not have passwords set. If not needed, do not expose the database port! If you need a password or want to use a remote database, you can configure it according to the official documentation (I can do it! 🥰)

  • JWT Secret: You need to fill in a string with a length of at least 16 characters and no more than 32 characters, used to encrypt the user's JWT. Be sure to keep your secret safe and do not disclose it to others.
  • Allowed Domains: You need to fill in the allowed domain names, usually the front-end domain. If multiple domains are allowed to access, separate them with commas.
  • (Optional) Enable Encryption: If you are sure you want to enable database encryption, change false to true. After enabling encryption, you need to fill in the encryption key below.
  • (Optional) Encryption Key: If you do not know what this is, it is not recommended to enable this feature. For specific content, refer to https://mx-space.js.org/usage/security.html

::: warning
This key is used to encrypt the database! If lost, backups cannot be restored! Be sure to record and save it!

If encryption is enabled, note that the key length must be 64 bits and consist only of lowercase letters and numbers, otherwise an error will occur during initialization. Note that this is irreversible, so be sure to save your secret. Therefore, it is not highly recommended to use unless you really need to encrypt the API Key.

The key can be generated using the command openssl rand -hex 32. Please remember it.

:::

Configuration Example

3. Start Core!#

cd /opt/mx-space/core
docker-compose pull && docker compose up -d

3. Reverse Proxy and Update#

1. Reverse Proxy#

Taking 1Panel + OpenResty as an example:

  • Create a static website
  • Configure SSL certificate to enable HTTPS
  • In the NGINX configuration file, above the last } add a new line, paste the following configuration, and save
Dual Domain Backend Reverse Proxy Example
    ## Reverse proxy starts
    ## WebSocket
    location /socket.io {
        proxy_pass http://127.0.0.1:2333/socket.io; 
        proxy_set_header Host $host; 
        proxy_set_header X-Real-IP $remote_addr; 
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header REMOTE-HOST $remote_addr; 
        proxy_set_header Upgrade $http_upgrade; 
        proxy_set_header Connection "upgrade"; 
        proxy_buffering off; 
        proxy_http_version 1.1; 
        add_header Cache-Control no-cache; 
    }
    ## Others
    location / {
        proxy_pass http://127.0.0.1:2333; 
        proxy_set_header Host $host; 
        proxy_set_header X-Real-IP $remote_addr; 
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header REMOTE-HOST $remote_addr; 
        add_header X-Cache $upstream_cache_status; 
    }
    ## Reverse proxy ends
Single Domain Frontend and Backend Reverse Proxy Example
## Reverse proxy starts, directly copy from the official documentation
    ## WebSocket address
    location /socket.io {
        proxy_set_header Upgrade $http_upgrade; 
        proxy_set_header Connection "Upgrade"; 
        proxy_buffering off; 
        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; 
    }
    ## API address
    location /api/v2 {
        proxy_pass http://127.0.0.1:2333/api/v2; 
    }
    ## Simple render address
    location /render {
        proxy_pass http://127.0.0.1:2333/render; 
    }
    ## Frontend address
    location / {
        proxy_pass http://127.0.0.1:2323; 
    }
    ## Backend address
    location /proxy {
        proxy_pass http://127.0.0.1:2333/proxy;
    }
    location /qaqdmin {
        proxy_pass http://127.0.0.1:2333/proxy/qaqdmin;
    }
    ## RSS address
    location ~* \/(feed|sitemap|atom.xml) {
        proxy_pass http://127.0.0.1:2333/$1; 
    }
    ## Reverse proxy ends
### 2. Core Initialization

After completing the reverse proxy configuration, access the backend at https://backend-domain/proxy/qaqdmin

Example: https://api.example.cc/proxy/qaqdmin

Complete the initialization according to the page prompts. If it does not correctly redirect to the backend after completion,
re-enter https://api.example.cc/proxy/qaqdmin.

3. Core Update#

cd /opt/mx-space/core
docker-compose pull && docker compose up -d

4. Reference Articles#

Debian 12 / Ubuntu 24.04 Install Docker and Docker Compose Tutorial

Official Deployment Documentation

This article is synchronized and updated by Mix Space to xLog. The original link is https://www.vlo.cc/posts/jc/mix-deploy

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.