A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
listen ${NGINX_HTTP_PORT} default_server;
listen [::]:${NGINX_HTTP_PORT} default_server;
server_name _;
resolver 127.0.0.11 valid=10s;
root /var/www/html/public;
index index.php;
charset utf-8;
error_log /var/log/nginx/error.log warn;
access_log /var/log/nginx/access.log custom if=$loggable;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location ~ /\.ht { deny all; }
location ^~ /up {
access_log off;
try_files $uri $uri/ /index.php;
}
location ~ ^/(app|apps)/ {
set $ws_upstream "ws:6001";
proxy_pass http://$ws_upstream;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Scheme $scheme;
proxy_set_header SERVER_PORT $server_port;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
proxy_intercept_errors on;
error_page 502 503 504 =404 /404;
}
# --- storage (user content, private) ---
location ~* ^/storage/media/ {
valid_referers 127.0.0.1, ${NGINX_APP_HOST};
if ($invalid_referer) { return 403; }
add_header Cache-Control "private, max-age=3600";
try_files $uri =404;
}
location ~* ^/storage/.*\.(woff|woff2|ttf)$ {
access_log off;
add_header Cache-Control "private, max-age=3600";
try_files $uri =404;
# 1h
}
# --- storage (images, mixed) ---
location ~* "^/storage/.*_[0-9a-f]{8,}\.(jpg|jpeg|png|gif|webp)$" {
access_log off;
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
# 1y (all hashed images so immutable)
}
location ~* ^/storage/.*/preview\.(webp|png|jpg|jpeg)$ {
access_log off;
add_header Cache-Control "public, max-age=300";
try_files $uri =404;
# 5m (external access)
}
location ~* ^/storage/.*/storyboard/\d+\.(jpg|jpeg|webp)$ {
access_log off;
add_header Cache-Control "private, max-age=30, must-revalidate";
try_files $uri =404;
# 5m (allows resets and holds user content information)
}
location ~* ^/storage/.*\.(jpg|jpeg|png|gif|webp)$ {
access_log off;
add_header Cache-Control "public, max-age=3600";
try_files $uri =404;
# 1h (default images or posters)
}
# --- build assets (public, immutable) ---
location ~* \.(js|css|map|woff|woff2|ttf)$ {
access_log off;
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
# 1y (hashed files so immutable)
}
location ~* \.(jpg|jpeg|png|gif|webp|svg|ico)$ {
access_log off;
add_header Cache-Control "public, max-age=2592000";
try_files $uri =404;
# 3d
}
location = /manifest.json {
access_log off;
add_header Cache-Control "public, max-age=3600" always;
add_header Content-Type "application/json" always;
add_header X-Served-By "nginx2" always;
try_files $uri =404;
}
# --- base ---
location / {
try_files $uri $uri/ /index.php?$query_string;
autoindex off;
}
location ~* ^/storage/.*\.php$ {
deny all;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffers $NGINX_FASTCGI_BUFFERS;
fastcgi_buffer_size $NGINX_FASTCGI_BUFFER_SIZE;
fastcgi_read_timeout $PHP_MAX_EXECUTION_TIME;
fastcgi_hide_header X-Powered-By;
}