Mastodon is the leading open-source, federated social network — part of the ActivityPub-based Fediverse that interconnects thousands of independently operated servers. Running your own Mastodon instance on a Hong Kong VPS lets you host a community platform with full moderation control, data sovereignty, and fast access for Asia-Pacific members via CN2 GIA routing — without dependence on centralised platforms or US-based moderation policies.
Use Cases for a Self-Hosted Mastodon Instance
- Niche communities — dedicated instances for specific interests: Japanese indie game developers, Hong Kong photographers, Taiwanese tech professionals
- Company social presence — a branded corporate Mastodon instance for announcements, developer relations, and community engagement
- Educational institutions — universities and schools running federated social platforms for students and alumni
- Alternative to X/Twitter — communities migrating from Twitter seeking self-hosted alternatives with predictable, community-controlled moderation
- Privacy-focused communities — groups prioritising data residency in Asia under local legal frameworks
VPS Requirements
| Instance Size | Users | RAM | vCPU | Storage |
|---|---|---|---|---|
| Personal / small team | 1–100 | 4 GB | 2 | 60 GB NVMe |
| Small community | 100–500 | 8 GB | 4 | 200 GB NVMe |
| Medium community | 500–5,000 | 16 GB | 8 | 500 GB NVMe |
| Large instance | 5,000+ | 32 GB+ | 16+ | Dedicated server |
Step 1: System Preparation
apt update && apt upgrade -y
apt install -y curl wget gnupg apt-transport-https lsb-release ca-certificates \
imagemagick ffmpeg libpq-dev libxml2-dev libxslt1-dev file git-core \
g++ libprotobuf-dev protobuf-compiler pkg-config gcc autoconf \
bison build-essential libssl-dev libyaml-dev libreadline6-dev \
zlib1g-dev libncurses5-dev libffi-dev libgdbm-dev \
nginx redis-server postgresql postgresql-contrib certbot \
python3-certbot-nginx ufw
# Configure firewall
ufw allow 22/tcp && ufw allow 80/tcp && ufw allow 443/tcp
ufw enable
Step 2: Deploy Mastodon with Docker (Recommended for Simplicity)
The Docker Compose approach is the most maintainable deployment method for most operators:
<code">apt install docker.io docker-compose-plugin -y systemctl enable --now docker # Create Mastodon user and directory useradd -m -d /home/mastodon -s /bin/bash mastodon mkdir -p /opt/mastodon && chown mastodon:mastodon /opt/mastodon su - mastodon
<code"># As mastodon user cd /opt/mastodon # Download official docker-compose.yml wget https://raw.githubusercontent.com/mastodon/mastodon/main/docker-compose.yml # Create .env.production (you'll fill this in after the wizard) touch .env.production
Generate Mastodon Configuration
# Run the interactive setup wizard
docker compose run --rm web bundle exec rake mastodon:setup
The wizard prompts for:
- Domain name (e.g.,
social.yourdomain.com) - Database credentials (use the PostgreSQL container defaults)
- Redis host (
redis— the Docker service name) - S3-compatible storage (optional — use local storage for small instances)
- SMTP settings for email verification
- Admin account details
The wizard generates your .env.production file with all required secrets. Copy the output and save it — you will need these values.
Start Mastodon
docker compose up -d
docker compose ps # Verify all services are running
Step 3: Configure Nginx as Reverse Proxy
cat > /etc/nginx/sites-available/mastodon << 'EOF'
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name social.yourdomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name social.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/social.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/social.yourdomain.com/privkey.pem;
keepalive_timeout 70;
sendfile on;
client_max_body_size 100m;
root /opt/mastodon/public;
gzip on;
location / {
try_files $uri @proxy;
}
location ~ ^/(emoji|packs|system/accounts/avatars|system/media_attachments/files) {
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri @proxy;
}
location @proxy {
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 https;
proxy_set_header Proxy "";
proxy_pass_header Server;
proxy_pass http://127.0.0.1:3000;
proxy_buffering on;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_cache_bypass $http_upgrade;
tcp_nodelay on;
}
location /api/v1/streaming {
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 https;
proxy_set_header Proxy "";
proxy_pass http://127.0.0.1:4000;
proxy_buffering off;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
tcp_nodelay on;
}
error_page 500 501 502 503 504 /500.html;
}
EOF
ln -s /etc/nginx/sites-available/mastodon /etc/nginx/sites-enabled/
certbot --nginx -d social.yourdomain.com
nginx -t && systemctl reload nginx
Step 4: Initial Instance Setup
# Create admin account (if not done via wizard)
docker compose exec web tootctl accounts create \
admin_username \
--email admin@yourdomain.com \
--confirmed \
--role Owner
Log in at https://social.yourdomain.com with your admin account. In Preferences → Administration → Server Settings:
- Set your instance name, contact email, and description
- Configure registration policy (open, approval-required, or invite-only)
- Set content retention policies
- Configure federation allowlist/blocklist if needed
Step 5: Moderation and Community Management
Running your own Mastodon instance gives you full moderation control:
- User roles: Owner, Admin, Moderator, User — assign appropriate roles to trusted community members
- Instance federation: Block problematic instances from federating with yours using the admin panel’s domain blocks
- Content warnings: Configure default sensitive content settings appropriate for your community
- Appeal system: Built-in moderation queue where users can appeal account suspensions
# Useful admin CLI commands
# List all accounts
docker compose exec web tootctl accounts list
# Suspend an account
docker compose exec web tootctl accounts modify username --suspend
# Purge media from a remote instance
docker compose exec web tootctl media remove --domain problematic-instance.example
# Remove old remote media (keeps your storage under control)
docker compose exec web tootctl media remove --days=30
Step 6: Media Storage Optimisation
Mastodon stores all media (avatars, header images, post attachments, cached remote media) locally by default. For instances expecting significant media volume, configure S3-compatible storage:
# In .env.production, add S3 configuration for Cloudflare R2 (zero egress):
S3_ENABLED=true
S3_BUCKET=mastodon-media
S3_REGION=auto
S3_ENDPOINT=https://YOUR_ACCOUNT.r2.cloudflarestorage.com
AWS_ACCESS_KEY_ID=YOUR_R2_KEY
AWS_SECRET_ACCESS_KEY=YOUR_R2_SECRET
# Restart after configuration change
docker compose up -d
Step 7: Automated Backups
<code">cat > /opt/mastodon-backup.sh << 'EOF' #!/bin/bash DATE=$(date +%Y%m%d_%H%M%S) BACKUP_DIR="/opt/backups/mastodon" mkdir -p $BACKUP_DIR # Database backup docker compose -f /opt/mastodon/docker-compose.yml exec -T db \ pg_dump -U mastodon mastodon_production | \ gzip > $BACKUP_DIR/mastodon_db_$DATE.sql.gz
# Local media backup (skip if using S3)
tar czf $BACKUP_DIR/mastodon_media_$DATE.tar.gz \
/opt/mastodon/public/system/ 2>/dev/null || true
# Keep 7 days
find $BACKUP_DIR -mtime +7 -delete
echo "Mastodon backup complete: $DATE"
EOF
chmod +x /opt/mastodon-backup.sh
crontab -l | { cat; echo "0 4 * * * /opt/mastodon-backup.sh"; } | crontab -
Updating Mastodon
<code">cd /opt/mastodon # Pull latest images docker compose pull # Run database migrations before starting new version docker compose run --rm web bundle exec rake db:migrate # Restart with new version docker compose up -d # Clear asset cache docker compose run --rm web bundle exec rake assets:precompile
Check the Mastodon releases page for upgrade notes — major versions occasionally require specific migration steps.
Conclusion
Running Mastodon on a Hong Kong VPS gives Asia-Pacific communities a fast, self-controlled social platform that federates with the global Fediverse while keeping data on infrastructure in your region. CN2 GIA routing makes the instance accessible to mainland Chinese community members, and full administrative control means moderation policies reflect your community’s values rather than a distant platform company’s.
Launch your community: Browse Server.HK Hong Kong VPS plans — a 4 GB plan handles a Mastodon instance for personal or small community use comfortably.