apt-get install -y ffmpeg
ffmpeg-static -i /var/www/html/mz/public/videos/producerai-hero.mp4 \ -vcodec libx264 -crf 32 -preset fast \ -movflags faststart \ -acodec aac -b:a 96k \ /var/www/html/mz/public/videos/hero-small.mp4
-############################################
# Tambah cache header untuk video di nginx config
cat > /etc/nginx/sites-available/mz << 'NGINX'
upstream avoer_app {
server 127.0.0.1:3001;
keepalive 64;
}
server {
listen 80;
listen [::]:80;
server_name avoer.ft.unsri.ac.id;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
# Static Next.js files
location /_next/static/ {
alias /var/www/html/mz/.next/static/;
expires 1y;
add_header Cache-Control "public, immutable";
access_log off;
}
# VIDEO — cache lama di browser, support range request untuk streaming
location /videos/ {
alias /var/www/html/mz/public/videos/;
expires 7d;
add_header Cache-Control "public, max-age=604800";
add_header Accept-Ranges bytes;
access_log off;
}
# Public folder lainnya
location /public/ {
alias /var/www/html/mz/public/;
expires 30d;
add_header Cache-Control "public";
access_log off;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
# Next.js app
location / {
proxy_pass http://avoer_app;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
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 $scheme;
proxy_cache_bypass $http_upgrade;
proxy_read_timeout 60s;
}
client_max_body_size 50M;
}
NGINX
nginx -t && nginx -s reload
echo "Nginx reload OK"
# Test video accessible langsung dari nginx (bukan via Next.js)
curl -I http://mz.com/videos/producerai-hero.mp4 | head -10