Jayden

Jayden

Deploy Mix Space using Docker Compose

Intro#

Previously, we have discussed how to deploy Mix Space. Now there is a more convenient method, let's share it.

This only includes the deployment content. For more detailed information, please refer to the article previously.

Install Docker#

If your server is in China, it is recommended to use Alibaba Cloud's image acceleration. The installation command is as follows:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

If you are outside of China, you can directly use the official script to install:

curl -fsSL https://get.docker.com | bash -s docker

If you have successfully installed Docker and Docker-Compose, you can check the versions with the following commands:

docker -v
docker compose version

Deploy Mix Space Core#

  1. Pull the configuration file
cd && mkdir -p $HOME/mix-space/core && cd $_ # Pull the docker-compose.yml file
wget https://fastly.jsdelivr.net/gh/mx-space/core@master/docker-compose.yml
  1. Create environment variables
vi .env
  1. After entering the following content, press the ESC key, then enter :wq to save and exit
JWT_SECRET= #JWT Secret: You need to fill in a string with a length of no less than 16 characters and no more than 32 characters as the JWT secret key for encrypting user JWT. Be sure to keep your key safe and do not disclose it to others.
ALLOWED_ORIGINS= #Allowed Origins: You need to fill in the allowed domain name, usually the domain name of the front-end. If multiple domain names are allowed to access, separate them with commas.
ENCRYPT_ENABLE= #If you are sure to enable encryption, change false to true. After enabling encryption, you need to fill in the encryption key below.
ENCRYPT_KEY= #If you don't know what this is, it is not recommended to enable this feature. For more information, please refer to https://mx-space.js.org/usage/security.html
  1. Start the backend
docker compose up -d

Deploy Frontend#

  1. Pull the configuration file
cd && mkdir -p $HOME/mix-space/core && cd $_ # Pull the docker-compose.yml file
wget https://raw.githubusercontent.com/Innei/Shiro/main/docker-compose.yml
  1. Pull the environment variables and modify the content
wget https://raw.githubusercontent.com/Innei/Shiro/main/.env.template .env
  1. Start the backend
docker compose up -d

Nginx Reverse Proxy#

  1. Resolve the domain name to the server.

  2. Apply for a certificate

    curl https://get.acme.sh | sh; apt install socat -y || yum install socat -y; ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
    ~/.acme.sh/acme.sh --issue -d xxu.do --standalone -k ec-256 --force --insecure
    mkdir -p /etc/pki/xxu.do
    ~/.acme.sh/acme.sh --installcert -d xxu.do --key-file /etc/pki/xxu.do/server.key --fullchain-file /etc/pki/xxu.do/server.crt
    service postfix reload;service dovecot reload;service nginx reload #Reload services
    
  3. Set up reverse proxy:

    vi /etc/nginx/nginx.conf
    

    Modify the domain name and certificate path in the example below, and add it to the configuration file:

Click to get the example
server {
    listen 80;
  rewrite ^(.*)$ https://$host$1 permanent;
    server_name xxu.do;
    index index.html; 
    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/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; 
    }
    location /.well-known/ {
           root /var/www/html;
    }
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name xxu.do;
    index index.html; 
    ssl_certificate     /etc/pki/xxu.do/server.crt;
    ssl_certificate_key /etc/pki/xxu.do/server.key;
    # *See "With SSL (Certbot)" below for details on automating ssl certificates
    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"; 

    ssl_session_cache shared:SSL:10m; 
    ssl_session_timeout 10m; 
    ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1; 
    error_page 497 https://$host$request_uri; 
    # limit_conn perserver 300; 
    # limit_conn perip 25; 
    # limit_rate 512k; 

    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/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; 
    }
    location /.well-known/ {
           root /var/www/html;
    }
}

Update#

Go to the core or frontend folder, then run

docker compose pull && docker compose up -d

This article is synchronized to xLog from Mix Space
The original link is https://xxu.do/posts/geek/deploy-Mix-Space-with-Docker-Compose


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