# Load the njs script js_path /etc/nginx/conf.d/; js_import emby2Pan from emby.js; js_import embyLive from emby-live.js; # Cache images, subtitles proxy_cache_path /var/cache/nginx/emby/images levels=1:2 keys_zone=emby_images:100m max_size=1g inactive=30d use_temp_path=off; proxy_cache_path /var/cache/nginx/emby/subtitles levels=1:2 keys_zone=emby_subtitles:10m max_size=1g inactive=30d use_temp_path=off; ## The below will force all nginx traffic to SSL, make sure all other server blocks only listen on 443 # server { # listen 80 default_server; # server_name _; # return 301 https://$host$request_uri; # } ## Start of actual server blocks server { listen443 ssl; server_name 你的域名; add_header'Referrer-Policy''no-referrer'; set$emby 内网emby地址; #emby/jellyfin address ssl_certificate /etc/nginx/ssl/ssl.pem; ssl_certificate_key /etc/nginx/ssl/ssl.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; gzipon; gzip_disable"msie6"; gzip_comp_level6; gzip_min_length1100; gzip_buffers168k; gzip_proxied any; gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/rss+xml image/svg+xml; ## The default `client_max_body_size` is 1M, this might not be enough for some posters, etc. client_max_body_size20M; # default is 4k subrequest_output_buffer_size200k; # # Security / XSS Mitigation Headers # add_header X-Frame-Options "SAMEORIGIN"; # add_header X-XSS-Protection "1; mode=block"; # add_header X-Content-Type-Options "nosniff"; # aliDrive direct stream need no-referrer add_header'Referrer-Policy''no-referrer';
# Proxy sockets traffic for jellyfin-mpv-shim and webClient location~* /(socket|embywebsocket) { # Proxy emby/jellyfin Websockets traffic proxy_pass$emby; ## WEBSOCKET SETTINGS ## Used to pass two way real time info to and from emby and the client. proxy_http_version1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $http_connection; 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_set_header X-Forwarded-Protocol $scheme; proxy_set_header X-Forwarded-Host $http_host; proxy_connect_timeout1h; proxy_send_timeout1h; proxy_read_timeout1h; tcp_nodelayon; ## Sends data as fast as it can not buffering large chunks, saves about 200ms per request. } # Cache the Subtitles location~* /videos/(.*)/Subtitles { proxy_pass$emby; 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_set_header X-Forwarded-Protocol $scheme; proxy_set_header X-Forwarded-Host $http_host;
proxy_cache emby_subtitles; proxy_cache_revalidateon; proxy_cache_lock_timeout10s; proxy_cache_lockon; proxy_cache_valid20030d; proxy_cache_key$request_uri; add_header X-Cache-Status $upstream_cache_status; # This is only to check if cache is working }
# Proxy PlaybackInfo location~ ^(.*)/proxy(/.*)$ { gunzipon; # Jellyfin has gzip,subrequest need this,Emby no gzip but compatible client_body_in_file_only clean; rewrite ^(.*)/proxy(/.*)$$1$2break; proxy_pass$emby$request_uri; # Emby need $request_uri,Jellyfin not need but compatible 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_set_header X-Forwarded-Protocol $scheme; proxy_set_header X-Forwarded-Host $http_host; # Disable buffering when the nginx proxy gets very resource heavy upon streaming proxy_bufferingoff; proxy_pass_request_bodyon; proxy_pass_request_headerson; add_header X-Proxy-Success "yes"; } location~* /Items/(.*)/PlaybackInfo { client_body_in_file_only clean; if ($args~* "IsPlayback=true") { js_content emby2Pan.transferPlaybackInfo; break; } proxy_pass$emby; } # Redirect the stream to njs location~* /videos/(.*)/stream { # Cache alist direct link add_header Cache-Control max-age=3600; js_content emby2Pan.redirect2Pan; } # Redirect the live to njs location~* /videos/(.*)/live { js_content embyLive.directLive; } location~* /videos/(.*)/master { js_content embyLive.directLive; } # Redirect Audio the stream to njs location~* /Audio/(.*)/universal { # Cache alist direct link add_header Cache-Control max-age=3600; js_content emby2Pan.redirect2Pan; } # for webClient download ,android is SyncService api location~* /Items/([^/]+)/Download { js_content emby2Pan.redirect2Pan; } # Emby for android download ,this is SyncService api only Emby location~* /Sync/JobItems/(.*)/File { # Cache alist direct link add_header Cache-Control max-age=3600; js_content emby2Pan.redirect2Pan; }
proxy_cache emby_images; proxy_cache_revalidateon; proxy_cache_lock_timeout10s; proxy_cache_lockon; proxy_cache_valid20030d; proxy_cache_key$request_uri; add_header X-Cache-Status $upstream_cache_status; # This is only to check if cache is working }
location / { # Proxy main emby/jellyfin traffic proxy_pass$emby; # client_max_body_size 1000M; ## Allows for mobile device large photo uploads. #proxy_set_header X-Real-IP $http_CF_Connecting_IP; ## if you use cloudflare un-comment this line and comment out above line. 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_set_header X-Forwarded-Protocol $scheme; proxy_set_header X-Forwarded-Host $http_host; # Disable buffering when the nginx proxy gets very resource heavy upon streaming proxy_bufferingoff;
## ADDITIONAL SECURITY SETTINGS ## ## Optional settings to improve security ## ## add these after you have completed your testing and ssl setup ## ## NOTICE: For the Strict-Transport-Security setting below, I would recommend ramping up to this value ## ## See https://hstspreload.org/ read through the "Deployment Recommendations" section first! ## # add_header 'Referrer-Policy' 'origin-when-cross-origin'; # add_header Strict-Transport-Security "max-age=15552000; preload" always; # add_header X-Frame-Options "SAMEORIGIN" always; # add_header X-Content-Type-Options "nosniff" always; # add_header X-XSS-Protection "1; mode=block" always; } }