Show pagesourceOld revisionsBacklinksBack to top Share via Share via... Twitter LinkedIn Facebook Pinterest Telegram WhatsApp Yammer RedditRecent ChangesSend via e-MailPrintPermalink × Table of Contents Mastodon (Federated Social Media) Installation of Docker and Nginx PostgreSQL database setup: (default test 'password') Start Set up Mastodon Start docker and connect required aqua network for reverse proxy: Nginx reverse proxy configuration Work in progress!! based on this thread. Mastodon (Federated Social Media) Installation of Docker and Nginx yum -y install https://mrmarkuz.dynu.net/mirror/mrmarkuz/7/noarch/nethserver-mrmarkuz-0.0.1-6.ns7.noarch.rpm yum -y install nethserver-docker nethserver-nginx curl -L "https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose mkdir /opt/mastodon cd /opt/mastodon Get docker-compose.yml from github: wget https://raw.githubusercontent.com/mastodon/mastodon/main/docker-compose.yml Comment the build statements to not build the images, this saves a lot of time (only needed if we like to change mastodon code) sed -i "s/ build/#build/g" docker-compose.yml PostgreSQL database setup: (default test 'password') docker run --name postgres14 -v /opt/mastodon/postgres14:/var/lib/postgresql/data -e POSTGRES_PASSWORD=password --rm -d postgres:14-alpine docker exec -it postgres14 psql -U postgres Enter the following commands: > CREATE USER mastodon WITH PASSWORD 'password' CREATEDB; > exit docker stop postgres14 Start Set up Mastodon touch .env.production docker-compose run --rm web bundle exec rake mastodon:setup It will take some time for this command to complete, and will eventually prompt you for setup information. Answer the questions as below: Question Enter Domain name: The FQDN you chose above Do you want to enable single user mode? No Are you using Docker to run Mastodon? Yes PostgreSQL host: mastodon-db-1 PostgreSQL port: 5432 Name of PostgreSQL database: mastodon Name of PostgreSQL user: mastodon Password of PostgreSQL user: password Redis host: mastodon-redis-1 Redis port: 6379 Redis password: (blank) Do you want to store uploaded files on the cloud? No Do you want to send e-mails from localhost? Yes E-mail address to send e-mails “from”: (press Enter) Send a test e-mail with this configuration right now? No Save configuration? Yes You’ll now be shown the contents of the configuration file, which will look like this: # Generated with mastodon:setup on 2022-11-03 12:27:03 UTC # Some variables in this file will be interpreted differently whether you are # using docker-compose or not. LOCAL_DOMAIN=toot.yourdomain.org SINGLE_USER_MODE=false SECRET_KEY_BASE=9adbeda17a4d0688f3a6b82b47a68a94ccbfd45e8c2cee20e9c0901d89b5985eb634e9e523fcb74c6702c06ffcc4ea97e3a5544304c4c6c97e97a6bbc2a5646d OTP_SECRET=5635320b899a14148473fbe6f8b740607e08c9327c93a058c86804d3ad5b8db5023d3732fb4c0eb17e73e8adac689cc62b84c4c88299556934bd8780b5e8e6a4 VAPID_PRIVATE_KEY=KNjW5mNneoMTkmPG0NPl5jh3CfEaXAath9PgNUUkMWI= VAPID_PUBLIC_KEY=BMWD6scX3Opxl9ROKZeFoSdr3olZWkNq--OblOgOIwhxbxOoDa6fMLcKAWf2lUNnZQcOMQVi7VpG8wYtJdjDi7w= DB_HOST=mastodon_db_1 DB_PORT=5432 DB_NAME=mastodon DB_USER=mastodon DB_PASS=password REDIS_HOST=mastodon_redis_1 REDIS_PORT=6379 REDIS_PASSWORD= SMTP_SERVER=localhost SMTP_PORT=25 SMTP_AUTH_METHOD=none SMTP_OPENSSL_VERIFY_MODE=none SMTP_FROM_ADDRESS=Mastodon <notifications@toot.yourdomain.org> Despite what the terminal tells you, the configuration file has not been saved. You’ll need to save it yourself, so in another terminal (keep this one open), run: cd /opt/mastodon nano .env.production Paste in these contents, save the file, and exit. Now return to the first terminal, where it’s asking more questions: Question Enter Prepare the database now? Yes Do you want to create an admin user straight away? Yes Username: Whatever you want; default is admin E-mail: A usable email address Start docker and connect required aqua network for reverse proxy: docker-compose up -d docker network connect aqua mastodon-web-1 Nginx reverse proxy configuration Add https redirect and reverse proxy by creating /etc/nginx/conf.d/mastodon.conf with following content and replace domain.org with the used domain name: map $http_upgrade $connection_upgrade { default upgrade; '' close; } server { listen 80; listen [::]:80; server_name domain.org; root /opt/mastodon/public; # Useful for Let's Encrypt location /.well-known/acme-challenge/ { allow all; } location / { return 301 https://$host$request_uri; } } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name domain.org; ssl_protocols TLSv1.2; ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_certificate /etc/pki/tls/certs/localhost.crt; ssl_certificate_key /etc/pki/tls/private/localhost.key; keepalive_timeout 70; sendfile on; client_max_body_size 80m; root /opt/mastodon/public; gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; add_header Strict-Transport-Security "max-age=31536000"; 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 /sw.js { add_header Cache-Control "public, max-age=0"; 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 off; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_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; } Disable httpd and enable nginx systemctl disable httpd --now systemctl enable nginx systemctl restart nginx Browse to the configured domain and login with admin mail and the noted password from the setup. wip How-To mastodon.txt Last modified: 2022/11/20 10:57by HF