Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save R0GGER/74d877d71b9867b3113f5766cbb442c6 to your computer and use it in GitHub Desktop.
Save R0GGER/74d877d71b9867b3113f5766cbb442c6 to your computer and use it in GitHub Desktop.
Invidious + Materialious + NGINX Proxy Manager

Why?

I had two major problems configuring and using Materialious with NGINX Proxy Manager;

Can't login - Materialious/Materialious#29
No thumbnails - Materialious/Materialious#24

How to run Invidious and Materialious with NGINX Proxy Manager

Invidious is single-threaded, therefore I choose to use a slightly different setup for a much better performance (multi-threaded).

Docker Compose - Invidious + Materialious

Edit:
domain: invidious.example.com
hmac_key: "CHANGE_ME!!"
VITE_DEFAULT_INVIDIOUS_INSTANCE: "https://invidious.example"

version: "3"
services:
    invidious:
        image: quay.io/invidious/invidious:latest
        deploy:
            replicas: 6
        restart: unless-stopped
        environment:
            INVIDIOUS_CONFIG: |
                channel_threads: 0
                feed_threads: 0
                db:
                    dbname: invidious
                    user: kemal
                    password: kemal
                    host: invidious-db
                    port: 5432
                check_tables: true
                external_port: 443
                domain: invidious.example.com
                https_only: true
                statistics_enabled: true                
                hmac_key: "CHANGE_ME!!"
        healthcheck:
            test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/trending || exit 1
            interval: 30s
            timeout: 5s
            retries: 2
        logging:
            options:
                max-size: "1G"
                max-file: "4"
        depends_on:
           - invidious-db

    invidious-refresh:
        image: quay.io/invidious/invidious:latest
        restart: unless-stopped
        environment:
            INVIDIOUS_CONFIG: |
                db:
                    dbname: invidious
                    user: kemal
                    password: kemal
                    host: invidious-db
                    port: 5432
                    check_tables: true
                check_tables: true
                external_port: 443
                domain: invidious.example.com
                https_only: true
                statistics_enabled: true                
                hmac_key: "CHANGE_ME!!"
        healthcheck:
            test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/trending || exit 1
            interval: 30s
            timeout: 5s
            retries: 2
        logging:
            options:
                max-size: "1G"
                max-file: "4"
        depends_on:
           - invidious-db 

    nginx:
        image: nginx:latest
        restart: unless-stopped
        volumes:
            - /opt/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
        depends_on:
            - invidious
        ports:
            - "3000:3000"

    invidious-db:
        image: docker.io/library/postgres:14
        restart: unless-stopped
        volumes:
          - postgresdata:/var/lib/postgresql/data
          - ./config/sql:/config/sql
          - ./docker/init-invidious-db.sh:/docker-entrypoint-initdb.d/init-invidious-db.sh
        environment:
            POSTGRES_DB: invidious
            POSTGRES_USER: kemal
            POSTGRES_PASSWORD: kemal
        healthcheck:
            test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]

    materialious:
        image: wardpearce/materialious:latest
        restart: unless-stopped
        ports:
        - 3001:80
        environment:     
             VITE_DEFAULT_INVIDIOUS_INSTANCE: "https://invidious.example"
             VITE_DEFAULT_RETURNYTDISLIKES_INSTANCE: "https://returnyoutubedislikeapi.com"
             VITE_DEFAULT_SPONSERBLOCK_INSTANCE: "https://sponsor.ajay.app"
             VITE_DEFAULT_DEARROW_INSTANCE: "https://sponsor.ajay.app"
             VITE_DEFAULT_DEARROW_THUMBNAIL_INSTANCE: "https://dearrow-thumb.ajay.app"
             VITE_DEFAULT_SETTINGS: '{"themeColor": "#2596be"}'
             
volumes:
    postgresdata:

Cron

Update your cronjobs to restart Invidious automatically.
crontab -e

0 */1 * * * docker restart invidious-invidious-1
1 */1 * * * docker restart invidious-invidious-2
2 */1 * * * docker restart invidious-invidious-3
3 */1 * * * docker restart invidious-invidious-4
4 */1 * * * docker restart invidious-invidious-5
5 */1 * * * docker restart invidious-invidious-6

NGINX Proxy Manager

Create 2 new Proxy Hosts.

1: materialious.example.com - 192.168.1.213:3001

Tab: Details - Create a new proxy host with SSL on (Let's Encrypt or your own certificate) and click SAVE.

2: invidious.example.com - 192.168.1.213:3000

  1. Tab: Details - Create a new proxy host with SSL on (Let's Encrypt or your own certificate).
  2. Tab: Custom locations, fill in IP and port. Click gear icon to add some security headers.
    v1pkZ86MFU

Add:

    if ($request_method = OPTIONS) {
      return 204;
    }

    proxy_hide_header Access-Control-Allow-Origin;
    add_header Access-Control-Allow-Credentials true;
    add_header Access-Control-Allow-Origin "https://materialious.example.com" always;
    add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, HEAD, PATCH, PUT, DELETE" always;
    add_header Access-Control-Allow-Headers "User-Agent, Authorization, Content-Type" always;

    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    proxy_http_version 1.1;

Edit:

add_header Access-Control-Allow-Origin "https://materialious.example.com" always;
  1. Click SAVE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment