Diaspora is an open-source, privacy-centric social media platform that empowers users to take control of their data by self-hosting their own "pod." It is a decentralized alternative to mainstream platforms, providing users with full ownership, customization, and the ability to connect to a global network of other Diaspora pods. In this guide, weβll walk through deploying Diaspora, configuring it with Nginx, enabling logging, setting up backups, keeping it updated, and leveraging its unique features.
Installing Diaspora
π¦ Docker/Docker Compose Setup
Using Docker simplifies the deployment process by encapsulating all dependencies. Hereβs how to create a docker-compose.yml
file and start Diaspora:
- Create a new directory for Diaspora:
mkdir diaspora && cd diaspora
- Create a
docker-compose.yml
file with the following configuration:
version: '3.7'
services:
diaspora:
image: diaspora/diaspora:latest
container_name: diaspora
restart: always
ports:
- "3000:3000"
volumes:
- diaspora-data:/home/diaspora/diaspora/public/uploads
environment:
DB_HOST: db
DB_USER: diaspora
DB_PASS: diasporadbpassword
DB_NAME: diaspora_production
RAILS_ENV: production
db:
image: postgres:13
container_name: diaspora_db
restart: always
environment:
POSTGRES_USER: diaspora
POSTGRES_PASSWORD: diasporadbpassword
POSTGRES_DB: diaspora_production
volumes:
- diaspora-db:/var/lib/postgresql/data
volumes:
diaspora-data:
diaspora-db:
- Start the containers:
docker-compose up -d
- Verify the containers are running:
docker ps
π Manual Installation
For a traditional setup on a Linux server, follow these steps:
- Install dependencies:
sudo apt update
sudo apt install -y git curl gnupg2 build-essential libssl-dev libreadline-dev libpq-dev zlib1g-dev libsqlite3-dev
- Clone the Diaspora repository:
git clone https://github.com/diaspora/diaspora.git
cd diaspora
- Install RVM (Ruby Version Manager) and Ruby:
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 3.0.0
rvm use 3.0.0 --default
- Install Bundler and dependencies:
gem install bundler
bundle install --deployment --without test development
- Configure the database and application:
cp config/database.yml.example config/database.yml
cp config/diaspora.yml.example config/diaspora.yml
- Run the setup script:
RAILS_ENV=production bin/rake db:create db:migrate
- Start Diaspora:
RAILS_ENV=production bin/bundle exec thin start
Configuring Nginx as a Reverse Proxy
π Nginx Configuration
To serve Diaspora, create an Nginx server block:
- Install Nginx:
sudo apt install nginx
- Create a new Nginx configuration file:
sudo nano /etc/nginx/sites-available/diaspora
- Add the following content:
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
- Enable the configuration:
sudo ln -s /etc/nginx/sites-available/diaspora /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
π SSL/TLS Setup
To secure the app with HTTPS:
- Install Certbot:
sudo apt install certbot python3-certbot-nginx
- Obtain and configure a certificate:
sudo certbot --nginx -d example.com
- Automate certificate renewal:
sudo crontab -e
Add the following line:
0 3 * * * certbot renew --quiet
Logging and Debugging Diaspora
ποΈ Enabling Debug Logs
Enable detailed logs by editing the diaspora.yml
file:
nano config/diaspora.yml
Set the log level to debug
:
logging:
level: debug
Restart Diaspora to apply the changes.
π Viewing Logs
For Docker:
docker logs -f diaspora
For manual installations:
tail -f log/production.log
π οΈ Troubleshooting Common Issues
Check for database connection errors or misconfigurations in the logs. Example:
grep "ActiveRecord::" log/production.log
Backup and Restore
ποΈ File-Based Backups
Backup uploads and configuration files:
tar -czvf diaspora_backup.tar.gz config/ public/uploads/
π Database Backups
Export the database:
pg_dump -U diaspora diaspora_production > diaspora_db_backup.sql
Restore the database:
psql -U diaspora diaspora_production < diaspora_db_backup.sql
π Automated Backup Scripts
Create a backup script /usr/local/bin/diaspora_backup.sh
:
#!/bin/bash
tar -czvf /backup/diaspora_$(date +%F).tar.gz config/ public/uploads/
pg_dump -U diaspora diaspora_production > /backup/diaspora_db_$(date +%F).sql
Make it executable:
chmod +x /usr/local/bin/diaspora_backup.sh
Schedule it via cron:
crontab -e
Add:
0 2 * * * /usr/local/bin/diaspora_backup.sh
Updating and Upgrading Diaspora
β¬οΈ Updating Docker Images
Pull the latest image and redeploy:
docker-compose pull
docker-compose up -d
π οΈ Manual Updates
For manual installs, update the source code:
git pull origin stable
bundle install --deployment --without development test
RAILS_ENV=production bin/rake db:migrate
Restart the application:
RAILS_ENV=production bin/bundle exec thin restart
Leveraging Diasporaβs Unique Features
π§ Enabling APIs
Enable the API in diaspora.yml
:
api:
enabled: true
Restart Diaspora, then test the API with curl
:
curl -X GET http://example.com/api/v1/users
π Advanced Configurations
To enable custom themes, place your files in public/custom/
and reference them in diaspora.yml
.
Wrapping Up
Diaspora puts privacy and control back into your hands, making it an excellent choice for self-hosting your social media platform. By following this guide, youβve set up Diaspora, secured it with Nginx, configured backups, and explored its features. Start connecting with a global community of other Diaspora pods while maintaining full ownership of your data!