Invidious
This guide is written sourcing this information:
It is designed to show how to setup an Invidious instance to be stable, low on resources and quick.
Requirements:
- Docker Engine
- Docker Compose
System Resoureces:
Minimum:
- 1 vCPU core per each Invidious instance (or per two)
- 8 GB free disk space
- ~ 512 MB of free RAM (recommended to have ~ 2 GB installed on the system)
Recommended:
- 2/4 vCPU cores
- At least 40 GB free disk space (For a public instance)
- 2 GB of free ram (4 GB on the host system)
Docker Repository
Invidious is available on Quay, here: invidious/invidious
Docker Compose (production) setup
This will use the pre-built docker image from quay.io
Setup
Clone the invidious repository.
Enter the invidious folder.
Compose File
Edit the docker-compose.yml file with the following content:
This is correct as of 2023-11-05. Check the up to date documentation here
version: "3"
services:
invidious:
image: quay.io/invidious/invidious:latest
# image: quay.io/invidious/invidious:latest-arm64 # ARM64/AArch64 devices
restart: unless-stopped
ports:
- "127.0.0.1:3000:3000"
environment:
# Please read the following file for a comprehensive list of all available
# configuration options and their associated syntax:
# https://github.com/iv-org/invidious/blob/master/config/config.example.yml
INVIDIOUS_CONFIG: |
db:
dbname: invidious
user: kemal
password: kemal
host: invidious-db
port: 5432
check_tables: true
# external_port:
# domain:
# https_only: false
# statistics_enabled: false
hmac_key: "CHANGE_ME!!"
healthcheck:
test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/comments/jNQXAC9IVRw || exit 1
interval: 30s
timeout: 5s
retries: 2
logging:
options:
max-size: "1G"
max-file: "4"
depends_on:
- invidious-db
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"]
volumes:
postgresdata:
It is recommended that you go through this docker-compose.yml file and check for details you may need to change, such as passwords.
You should change the hmac_key.
Generate HMAC key
On Linux, you can generate a HMAC key using the following command.
Or
Source: Invidious Docs
If you prefer to directly access Invidious, replace 127.0.0.1:3000:3000 with 3000:3000. However, ignore this if you are planning to follow with the guide later on.
Start Invidious
Invidious is now setup.
Start Invidious using Docker Compose.
This will run the docker compose file for Invidious, and run it in the background as a daemon.
If you would like to view the logs, run the following command.
Updating Invidious
It is a good idea to update Invidious often.
Start by pulling the changes since your last pull from the Quay.io repository.
Start Invidious with the updated Invidious
Prune un-needed docker images.
Cronjob to restart Invidious
Invidious is not always stable, and will also require restarting the Invidious container to update subscriptions quicker.
Add this to your crontab.
Choose the editor of your choice.
Save the file.
The docker container name may not be correct, so you should check this using docker ps
Setup NGINX reverse proxy with Invidious
If you would prefer to setup an NGINX reverse proxy using Invidious, it will allow SSL certificates and allow finer control with reverse proxying your Invidious instance.
It is recommended to install NGINX on your host system, such as through APT.
Edit NGINX reverse proxy configuration
Edit the existing NGINX configuration. If you do not need/have anything else in this file required, you can empty the file and input the following.
server {
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name invidious.domain.tld;
access_log off;
error_log /var/log/nginx/error.log crit;
ssl_certificate /etc/letsencrypt/live/invidious.domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/invidious.domain.tld/privkey.pem;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host; # so Invidious knows domain
proxy_http_version 1.1; # to keep alive
proxy_set_header Connection ""; # to keep alive
}
if ($https = '') { return 301 https://$host$request_uri; } # if not connected to HTTPS, perma-redirect to HTTPS
}
This is an example.
It will listen on port 80 and port 443 for HTTP traffic.
Replace the server_name variable with your invidious domain/subdomain of choice.
You should point this domain/subdomain at the IP address of your Invidious instance.
Do not forget to make sure that the SSL certificates for your site are stored correctly in /etc/letsencrypt/live/YOUR_DOMAIN_HERE
If the folder does not exist, you should create it.
By default, this configuration disabled all logs.
Optimizing Invidious
By optimizing Invidious, you can improve the performance and loading speed while also decreasing the memory and CPU consumption of your Invidious instance on your server.
It is recommended to use Docker.
Multiple Invidious instances
Remove port binding
Inside your docker-compose.yml file, remove the following lines. These currently bind the port of Invidious.
Create Invidious start BASH script
Create a new bash script, and name it start.sh.
This will allow you to run multiple containers of the same Docker image (Invidious).
- You can change the amount to any, but this example shows 6 Invidious containers.
You should NOT restart Invidious yet.
Setup NGINX as a load balancer
Create a file named nginx.conf.
Important: This is not your host's NGINX configuration, but instead inside the same folder as your docker-compose.yml file is in. This will run as an NGINX container.
Input the following:
user www-data;
events {
worker_connections 1000;
}
http {
server {
listen 3000;
listen [::]:3000;
access_log off;
location / {
proxy_pass http://invidious:3000;
proxy_http_version 1.1; # to keep alive
proxy_set_header Connection ""; # to keep alive
}
}
}
Add a new service (NGINX container) inside your docker-compose.yml file.
nginx:
image: nginx:latest
restart: unless-stopped
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- invidious
ports:
- "127.0.0.1:3000:3000"
Update your cronjob to restart Invidious.
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
This example shows with 6 containers. If you are not running 6 containers, adjust the file accordingly.
Each CRON within this cronjob will run at different times to avoid disrupting your Invidious instance due to a restart.
Speed up video playback using http3-ytproxy
This will use TeamPiped/http3-ytproxy.
NGINX configuration is used for this part. It is recommended to setup this on your main NGINX reverse proxy (such as on your host system).
Find the username of the NGINX process.
Look at the top of the /etc/nginx/nginx.conf file.
It typically will be 33. If not, adjust the following commands.
Create a new directory for the service, and give the correct permissions for the NGINX user.
Add the new service to your docker-compose.yml file.
http3-ytproxy:
image: 1337kavin/ytproxy:latest
restart: unless-stopped
user: 33:33
environment:
- DISABLE_WEBP=1
volumes:
- /opt/http3-ytproxy:/app/socket
Add the following for the server section of Invidious in your NGINX configuration. This should be after the block showing location /.
location ~ (^/videoplayback|^/vi/|^/ggpht/|^/sb/) {
proxy_buffering on;
proxy_buffers 1024 16k;
proxy_set_header X-Forwarded-For "";
proxy_set_header CF-Connecting-IP "";
proxy_hide_header "alt-svc";
sendfile on;
sendfile_max_chunk 512k;
tcp_nopush on;
aio threads=default;
aio_write on;
directio 16m;
proxy_hide_header Cache-Control;
proxy_hide_header etag;
proxy_http_version 1.1;
proxy_set_header Connection keep-alive;
proxy_max_temp_file_size 32m;
access_log off;
proxy_pass http://unix:/opt/http3-ytproxy/http-proxy.sock;
add_header Cache-Control private always;
}
If you are using NGINX (with multiple Invidious processes), you will need to add this new volume to your docker-compose.yml file.
Final steps
Reload docker.
(This is only if you have multiple Invidious instances)
Reload NGINX.
You should now have multiple Invidious instances, with NGINX acting as a load balancer.
This should have Invidious run with better performance and stability.
This guide has been written by adaptions from the unixfox guide, and the Invidious docs