From 9423092bc6fb52753ab2110c896bc1ae7fff2318 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Mon, 8 Nov 2021 16:01:24 +0100 Subject: [PATCH] Initial commit --- nextcloud.nix | 20 ++ peertube.nginx.conf | 155 +++++++++++++ peertube.nix | 44 ++++ production.yaml | 544 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 763 insertions(+) create mode 100644 nextcloud.nix create mode 100644 peertube.nginx.conf create mode 100644 peertube.nix create mode 100644 production.yaml diff --git a/nextcloud.nix b/nextcloud.nix new file mode 100644 index 0000000..b05f1a6 --- /dev/null +++ b/nextcloud.nix @@ -0,0 +1,20 @@ +{ + pkgs ? import {} +}: + +pkgs.mkShell { + shellHook = '' + NEXTCLOUD=${pkgs.nextcloud22} + function deploy { + rm -rf /tmp/nextcloud + cp -r $NEXTCLOUD/ /tmp/nextcloud + cd /tmp/nextcloud + chmod +w -R . + php -S 0.0.0.0:9000 + } + ''; + nativeBuildInputs = [ + pkgs.nextcloud22 + pkgs.php80 + ]; +} diff --git a/peertube.nginx.conf b/peertube.nginx.conf new file mode 100644 index 0000000..0cd6c2d --- /dev/null +++ b/peertube.nginx.conf @@ -0,0 +1,155 @@ +daemon off; +error_log /dev/stderr; +user nobody nobody; + +events {} + +http { + ## + # Basic Settings + ## + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + client_body_temp_path /tmp/nginx-cache-client 1 2; + proxy_temp_path /tmp/nginx-cache-proxy 1 2; + + # + # SSL Settings + ## + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + ## + # Gzip Settings + ## + gzip on; + + access_log /dev/stdout; + server_names_hash_bucket_size 64; + + upstream backend { + server 127.0.0.1:9000; + } + +server { + # In production you should use TLS instead of plain HTTP + listen [::]:443 http2 ssl; + + # should be the endpoint you want + # aws uses s3.amazonaws.com for example + server_name garage.example.com; + + location / { + proxy_pass http://s3_backend; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + } +} + + + server { + listen [::]:80; + + server_name peertube.localhost; + + ## + # Application + ## + + location @api { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + + client_max_body_size 100k; # default is 1M + + proxy_connect_timeout 10m; + proxy_send_timeout 10m; + proxy_read_timeout 10m; + send_timeout 10m; + + proxy_pass http://backend; + } + + location / { + try_files /dev/null @api; + } + + location = /api/v1/videos/upload-resumable { + client_max_body_size 0; + proxy_request_buffering off; + + try_files /dev/null @api; + } + + location = /api/v1/videos/upload { + limit_except POST HEAD { deny all; } + + # This is the maximum upload size, which roughly matches the maximum size of a video file. + # Note that temporary space is needed equal to the total size of all concurrent uploads. + # This data gets stored in /var/lib/nginx by default, so you may want to put this directory + # on a dedicated filesystem. + client_max_body_size 12G; # default is 1M + add_header X-File-Maximum-Size 8G always; # inform backend of the set value in bytes before mime-encoding (x * 1.4 >= client_max_body_size) + + try_files /dev/null @api; + } + + location ~ ^/api/v1/(videos|video-playlists|video-channels|users/me) { + client_max_body_size 6M; # default is 1M + add_header X-File-Maximum-Size 4M always; # inform backend of the set value in bytes before mime-encoding (x * 1.4 >= client_max_body_size) + + try_files /dev/null @api; + } + + ## + # Websocket + ## + + location @api_websocket { + proxy_http_version 1.1; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + + proxy_pass http://backend; + } + + location /socket.io { + try_files /dev/null @api_websocket; + } + + location /tracker/socket { + # Peers send a message to the tracker every 15 minutes + # Don't close the websocket before then + proxy_read_timeout 15m; # default is 60s + + try_files /dev/null @api_websocket; + } +} + + server { + listen [::]:80; + + server_name peertube-video.garage.localhost peertube-playlist.garage.localhost; + + + location / { + add_header Access-Control-Allow-Origin *; + add_header Access-Control-Max-Age 3600; + add_header Access-Control-Expose-Headers Content-Length; + add_header Access-Control-Allow-Headers Range; + if ($request_method !~ ^(GET|HEAD)$ ) { + return 200; + } + proxy_pass http://127.0.0.1:3902; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + } + } +} diff --git a/peertube.nix b/peertube.nix new file mode 100644 index 0000000..ce93ce5 --- /dev/null +++ b/peertube.nix @@ -0,0 +1,44 @@ +{ + pkgs ? import {} +}: + +with pkgs; mkShell { + shellHook = '' + PEERTUBE=${peertube} + function deploy { + rm -rf /tmp/peertube + mkdir -p /tmp/peertube/{config,storage} + cp -r $PEERTUBE /tmp/peertube/code + mkdir /tmp/psql + initdb -D /tmp/psql/ --no-locale --encoding=UTF8 + pg_ctl -D /tmp/psql -l logfile -o "--unix_socket_directories='$PWD'" start + createdb -h $PWD peertube + psql -h $PWD peertube -c "CREATE EXTENSION pg_trgm;" + psql -h $PWD peertube -c "CREATE EXTENSION unaccent;" + cp $PEERTUBE/config/default.yaml /tmp/peertube/config/default.yaml + cp production.yaml /tmp/peertube/config/production.yaml + echo "edit production.yaml" + # redis-server + echo "Launch redis-server in a separate shell" + cd /tmp/peertube/code + export NODE_ENV=production + export NODE_CONFIG_DIR=/tmp/peertube/config + node dist/server.js + # pg_ctl -D /tmp/psql stop + # stop redis + } + ''; + nativeBuildInputs = [ + peertube + postgresql_14 + curl + unzip + nodejs-16_x + yarn + ffmpeg + openssl + redis + gcc + nginx + ]; +} diff --git a/production.yaml b/production.yaml new file mode 100644 index 0000000..4379a20 --- /dev/null +++ b/production.yaml @@ -0,0 +1,544 @@ +listen: + hostname: 'localhost' + port: 9000 + +# Correspond to your reverse proxy server_name/listen configuration (i.e., your public PeerTube instance URL) +webserver: + https: false + hostname: 'localhost' + port: 9000 + +rates_limit: + api: + # 50 attempts in 10 seconds + window: 10 seconds + max: 50 + login: + # 15 attempts in 5 min + window: 5 minutes + max: 15 + signup: + # 2 attempts in 5 min (only succeeded attempts are taken into account) + window: 5 minutes + max: 2 + ask_send_email: + # 3 attempts in 5 min + window: 5 minutes + max: 3 + +# Proxies to trust to get real client IP +# If you run PeerTube just behind a local proxy (nginx), keep 'loopback' +# If you run PeerTube behind a remote proxy, add the proxy IP address (or subnet) +trust_proxy: + - 'loopback' + +# Your database name will be database.name OR "peertube"+database.suffix +database: + hostname: '/home/quentin/Documents/dev/deuxfleurs/garage-tests' + name: 'peertube' + username: 'quentin' + pool: + max: 5 + +# Redis server for short time storage +# You can also specify a 'socket' path to a unix socket but first need to +# comment out hostname and port +redis: + hostname: 'localhost' + port: 6379 + auth: null + db: 0 + +# SMTP server to send emails +smtp: + # smtp or sendmail + transport: smtp + # Path to sendmail command. Required if you use sendmail transport + sendmail: null + hostname: null + port: 465 # If you use StartTLS: 587 + username: null + password: null + tls: true # If you use StartTLS: false + disable_starttls: false + ca_file: null # Used for self signed certificates + from_address: 'admin@example.com' + +email: + body: + signature: "PeerTube" + subject: + prefix: "[PeerTube]" + +# From the project root directory +storage: + tmp: '/tmp/peertube/storage/tmp/' # Use to download data (imports etc), store uploaded files before and during processing... + avatars: '/tmp/peertube/storage/avatars/' + videos: '/tmp/peertube/storage/videos/' + streaming_playlists: '/tmp/peertube/storage/streaming-playlists/' + redundancy: '/tmp/peertube/storage/redundancy/' + logs: '/tmp/peertube/storage/logs/' + previews: '/tmp/peertube/storage/previews/' + thumbnails: '/tmp/peertube/storage/thumbnails/' + torrents: '/tmp/peertube/storage/torrents/' + captions: '/tmp/peertube/storage/captions/' + cache: '/tmp/peertube/storage/cache/' + plugins: '/tmp/peertube/storage/plugins/' + # Overridable client files : logo.svg, favicon.png and icons/*.png (PWA) in client/dist/assets/images + # Could contain for example assets/images/favicon.png + # If the file exists, peertube will serve it + # If not, peertube will fallback to the default file + client_overrides: '/tmp/peertube/storage/client-overrides/' + +object_storage: + enabled: false + + # Without protocol, will default to HTTPS + endpoint: '' # 's3.amazonaws.com' or 's3.fr-par.scw.cloud' for example + + region: 'us-east-1' + + credentials: + # You can also use AWS_ACCESS_KEY_ID env variable + access_key_id: '' + # You can also use AWS_SECRET_ACCESS_KEY env variable + secret_access_key: '' + + # Maximum amount to upload in one request to object storage + max_upload_part: 2GB + + streaming_playlists: + bucket_name: 'streaming-playlists' + + # Allows setting all buckets to the same value but with a different prefix + prefix: '' # Example: 'streaming-playlists:' + + # Base url for object URL generation, scheme and host will be replaced by this URL + # Useful when you want to use a CDN/external proxy + base_url: '' # Example: 'https://mirror.example.com' + + # Same settings but for webtorrent videos + videos: + bucket_name: 'videos' + prefix: '' + base_url: '' + +log: + level: 'info' # 'debug' | 'info' | 'warn' | 'error' + rotation: + enabled : true # Enabled by default, if disabled make sure that 'storage.logs' is pointing to a folder handled by logrotate + maxFileSize: 12MB + maxFiles: 20 + anonymizeIP: false + log_ping_requests: true + prettify_sql: false + +trending: + videos: + interval_days: 7 # Compute trending videos for the last x days + algorithms: + enabled: + - 'best' # adaptation of Reddit's 'Best' algorithm (Hot minus History) + - 'hot' # adaptation of Reddit's 'Hot' algorithm + - 'most-viewed' # default, used initially by PeerTube as the trending page + - 'most-liked' + default: 'most-viewed' + +# Cache remote videos on your server, to help other instances to broadcast the video +# You can define multiple caches using different sizes/strategies +# Once you have defined your strategies, choose which instances you want to cache in admin -> manage follows -> following +redundancy: + videos: + check_interval: '1 hour' # How often you want to check new videos to cache + strategies: # Just uncomment strategies you want +# - +# size: '10GB' +# # Minimum time the video must remain in the cache. Only accept values > 10 hours (to not overload remote instances) +# min_lifetime: '48 hours' +# strategy: 'most-views' # Cache videos that have the most views +# - +# size: '10GB' +# # Minimum time the video must remain in the cache. Only accept values > 10 hours (to not overload remote instances) +# min_lifetime: '48 hours' +# strategy: 'trending' # Cache trending videos +# - +# size: '10GB' +# # Minimum time the video must remain in the cache. Only accept values > 10 hours (to not overload remote instances) +# min_lifetime: '48 hours' +# strategy: 'recently-added' # Cache recently added videos +# min_views: 10 # Having at least x views + +# Other instances that duplicate your content +remote_redundancy: + videos: + # 'nobody': Do not accept remote redundancies + # 'anybody': Accept remote redundancies from anybody + # 'followings': Accept redundancies from instance followings + accept_from: 'anybody' + +csp: + enabled: false + report_only: true # CSP directives are still being tested, so disable the report only mode at your own risk! + report_uri: + +security: + # Set the X-Frame-Options header to help to mitigate clickjacking attacks + frameguard: + enabled: true + +tracker: + # If you disable the tracker, you disable the P2P aspect of PeerTube + enabled: true + # Only handle requests on your videos. + # If you set this to false it means you have a public tracker. + # Then, it is possible that clients overload your instance with external torrents + private: true + # Reject peers that do a lot of announces (could improve privacy of TCP/UDP peers) + reject_too_many_announces: false + +history: + videos: + # If you want to limit users videos history + # -1 means there is no limitations + # Other values could be '6 months' or '30 days' etc (PeerTube will periodically delete old entries from database) + max_age: -1 + +views: + videos: + # PeerTube creates a database entry every hour for each video to track views over a period of time + # This is used in particular by the Trending page + # PeerTube could remove old remote video views if you want to reduce your database size (video view counter will not be altered) + # -1 means no cleanup + # Other values could be '6 months' or '30 days' etc (PeerTube will periodically delete old entries from database) + remote: + max_age: '30 days' + +plugins: + # The website PeerTube will ask for available PeerTube plugins and themes + # This is an unmoderated plugin index, so only install plugins/themes you trust + index: + enabled: true + check_latest_versions_interval: '12 hours' # How often you want to check new plugins/themes versions + url: 'https://packages.joinpeertube.org' + +federation: + videos: + federate_unlisted: false + + # Add a weekly job that cleans up remote AP interactions on local videos (shares, rates and comments) + # It removes objects that do not exist anymore, and potentially fix their URLs + # This setting is opt-in because due to an old bug in PeerTube, remote rates sent by instance before PeerTube 3.0 will be deleted + # We still suggest you to enable this setting even if your users will loose most of their video's likes/dislikes + cleanup_remote_interactions: false + +peertube: + check_latest_version: + # Check and notify admins of new PeerTube versions + enabled: true + # You can use a custom URL if your want, that respect the format behind https://joinpeertube.org/api/v1/versions.json + url: 'https://joinpeertube.org/api/v1/versions.json' + +############################################################################### +# +# From this point, all the following keys can be overridden by the web interface +# (local-production.json file). If you need to change some values, prefer to +# use the web interface because the configuration will be automatically +# reloaded without any need to restart PeerTube. +# +# /!\ If you already have a local-production.json file, the modification of the +# following keys will have no effect /!\. +# +############################################################################### + +cache: + previews: + size: 500 # Max number of previews you want to cache + captions: + size: 500 # Max number of video captions/subtitles you want to cache + torrents: + size: 500 # Max number of video torrents you want to cache + +admin: + # Used to generate the root user at first startup + # And to receive emails from the contact form + email: 'admin@example.com' + +contact_form: + enabled: true + +signup: + enabled: false + limit: 10 # When the limit is reached, registrations are disabled. -1 == unlimited + minimum_age: 16 + requires_email_verification: false + filters: + cidr: # You can specify CIDR ranges to whitelist (empty = no filtering) or blacklist + whitelist: [] + blacklist: [] + +user: + # Default value of maximum video BYTES the user can upload (does not take into account transcoded files). + # -1 == unlimited + video_quota: -1 + video_quota_daily: -1 + +# If enabled, the video will be transcoded to mp4 (x264) with "faststart" flag +# In addition, if some resolutions are enabled the mp4 video file will be transcoded to these new resolutions. +# Please, do not disable transcoding since many uploaded videos will not work +transcoding: + enabled: true + + # Allow your users to upload .mkv, .mov, .avi, .wmv, .flv, .f4v, .3g2, .3gp, .mts, m2ts, .mxf, .nut videos + allow_additional_extensions: true + + # If a user uploads an audio file, PeerTube will create a video by merging the preview file and the audio file + allow_audio_files: true + + # Amount of threads used by ffmpeg for 1 transcoding job + threads: 1 + # Amount of transcoding jobs to execute in parallel + concurrency: 1 + + # Choose the transcoding profile + # New profiles can be added by plugins + # Available in core PeerTube: 'default' + profile: 'default' + + resolutions: # Only created if the original video has a higher resolution, uses more storage! + 0p: false # audio-only (creates mp4 without video stream, always created when enabled) + 240p: false + 360p: false + 480p: false + 720p: false + 1080p: false + 1440p: false + 2160p: false + + # Generate videos in a WebTorrent format (what we do since the first PeerTube release) + # If you also enabled the hls format, it will multiply videos storage by 2 + # If disabled, breaks federation with PeerTube instances < 2.1 + webtorrent: + enabled: false + + # /!\ Requires ffmpeg >= 4.1 + # Generate HLS playlists and fragmented MP4 files. Better playback than with WebTorrent: + # * Resolution change is smoother + # * Faster playback in particular with long videos + # * More stable playback (less bugs/infinite loading) + # If you also enabled the webtorrent format, it will multiply videos storage by 2 + hls: + enabled: true + +live: + enabled: false + + # Limit lives duration + # -1 == unlimited + max_duration: -1 # For example: '5 hours' + + # Limit max number of live videos created on your instance + # -1 == unlimited + max_instance_lives: 20 + + # Limit max number of live videos created by a user on your instance + # -1 == unlimited + max_user_lives: 3 + + # Allow your users to save a replay of their live + # PeerTube will transcode segments in a video file + # If the user daily/total quota is reached, PeerTube will stop the live + # /!\ transcoding.enabled (and not live.transcoding.enabled) has to be true to create a replay + allow_replay: true + + # Your firewall should accept traffic from this port in TCP if you enable live + rtmp: + port: 1935 + + # Allow to transcode the live streaming in multiple live resolutions + transcoding: + enabled: true + threads: 2 + + # Choose the transcoding profile + # New profiles can be added by plugins + # Available in core PeerTube: 'default' + profile: 'default' + + resolutions: + 240p: false + 360p: false + 480p: false + 720p: false + 1080p: false + 1440p: false + 2160p: false + +import: + # Add ability for your users to import remote videos (from YouTube, torrent...) + videos: + # Amount of import jobs to execute in parallel + concurrency: 1 + + http: # Classic HTTP or all sites supported by youtube-dl https://rg3.github.io/youtube-dl/supportedsites.html + enabled: false + + # IPv6 is very strongly rate-limited on most sites supported by youtube-dl + force_ipv4: false + + # You can use an HTTP/HTTPS/SOCKS proxy with youtube-dl + proxy: + enabled: false + url: "" + torrent: # Magnet URI or torrent file (use classic TCP/UDP/WebSeed to download the file) + enabled: false + +auto_blacklist: + # New videos automatically blacklisted so moderators can review before publishing + videos: + of_users: + enabled: false + +# Instance settings +instance: + name: 'PeerTube' + short_description: 'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.' + description: 'Welcome to this PeerTube instance!' # Support markdown + terms: 'No terms for now.' # Support markdown + code_of_conduct: '' # Supports markdown + + # Who moderates the instance? What is the policy regarding NSFW videos? Political videos? etc + moderation_information: '' # Supports markdown + + # Why did you create this instance? + creation_reason: '' # Supports Markdown + + # Who is behind the instance? A single person? A non profit? + administrator: '' # Supports Markdown + + # How long do you plan to maintain this instance? + maintenance_lifetime: '' # Supports Markdown + + # How will you pay the PeerTube instance server? With your own funds? With users donations? Advertising? + business_model: '' # Supports Markdown + + # If you want to explain on what type of hardware your PeerTube instance runs + # Example: "2 vCore, 2GB RAM..." + hardware_information: '' # Supports Markdown + + # What are the main languages of your instance? To interact with your users for example + # Uncomment or add the languages you want + # List of supported languages: https://peertube.cpy.re/api/v1/videos/languages + languages: +# - en +# - es +# - fr + + # You can specify the main categories of your instance (dedicated to music, gaming or politics etc) + # Uncomment or add the category ids you want + # List of supported categories: https://peertube.cpy.re/api/v1/videos/categories + categories: +# - 1 # Music +# - 2 # Films +# - 3 # Vehicles +# - 4 # Art +# - 5 # Sports +# - 6 # Travels +# - 7 # Gaming +# - 8 # People +# - 9 # Comedy +# - 10 # Entertainment +# - 11 # News & Politics +# - 12 # How To +# - 13 # Education +# - 14 # Activism +# - 15 # Science & Technology +# - 16 # Animals +# - 17 # Kids +# - 18 # Food + + default_client_route: '/videos/trending' + + # Whether or not the instance is dedicated to NSFW content + # Enabling it will allow other administrators to know that you are mainly federating sensitive content + # Moreover, the NSFW checkbox on video upload will be automatically checked by default + is_nsfw: false + # By default, "do_not_list" or "blur" or "display" NSFW videos + # Could be overridden per user with a setting + default_nsfw_policy: 'do_not_list' + + customizations: + javascript: '' # Directly your JavaScript code (without