nixos/hosts/architect/plex.nix

80 lines
3.0 KiB
Nix
Raw Permalink Normal View History

2023-06-26 19:49:52 +01:00
{ pkgs, config, ... }:
2021-08-27 09:24:16 +01:00
let
2023-06-26 19:49:52 +01:00
domain = "media.giugl.io";
2023-05-01 04:50:42 +01:00
port = 32400;
2023-02-11 02:29:48 +00:00
in
{
2023-05-01 04:50:42 +01:00
architect.firewall = {
openTCP = [ 32400 3005 8324 32469 ];
openUDP = [ 1900 5353 32410 32412 32413 32414 ];
};
2021-08-27 09:24:16 +01:00
services.plex = {
enable = true;
package = pkgs.unstablePkgs.plex;
2023-06-26 19:49:52 +01:00
dataDir = "/plex";
2021-08-27 09:24:16 +01:00
};
2021-08-07 12:38:18 +01:00
2023-06-26 19:49:52 +01:00
architect.vhost.${domain} = with config.architect.networks; {
2023-10-21 14:00:58 +01:00
dnsInterfaces = [ "lan" "tailscale" ];
2023-06-26 19:49:52 +01:00
locations = {
"/" = {
inherit port;
2023-05-01 04:50:42 +01:00
2023-06-26 19:49:52 +01:00
proxyWebsockets = true;
2023-11-17 12:18:22 +00:00
allowLan = true;
allow = [
tailscale.net
];
2023-06-26 19:49:52 +01:00
extraConfig = ''
#Some players don't reopen a socket and playback stops totally instead of resuming after an extended pause
send_timeout 100m;
2021-08-07 12:38:18 +01:00
2023-06-26 19:49:52 +01:00
# Forward real ip and host to Plex
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 Host $server_addr;
proxy_set_header Referer $server_addr;
proxy_set_header Origin $server_addr;
2021-08-07 12:38:18 +01:00
2023-06-26 19:49:52 +01:00
# Plex has A LOT of javascript, xml and html. This helps a lot, but if it causes playback issues with devices turn it off.
gzip on;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css text/xml application/xml text/javascript application/x-javascript image/svg+xml;
gzip_disable "MSIE [1-6]\.";
2021-08-07 12:38:18 +01:00
2023-06-26 19:49:52 +01:00
# Nginx default client_max_body_size is 1MB, which breaks Camera Upload feature from the phones.
# Increasing the limit fixes the issue. Anyhow, if 4K videos are expected to be uploaded, the size might need to be increased even more
client_max_body_size 100M;
2021-08-07 12:38:18 +01:00
2023-06-26 19:49:52 +01:00
# Plex headers
proxy_set_header X-Plex-Client-Identifier $http_x_plex_client_identifier;
proxy_set_header X-Plex-Device $http_x_plex_device;
proxy_set_header X-Plex-Device-Name $http_x_plex_device_name;
proxy_set_header X-Plex-Platform $http_x_plex_platform;
proxy_set_header X-Plex-Platform-Version $http_x_plex_platform_version;
proxy_set_header X-Plex-Product $http_x_plex_product;
proxy_set_header X-Plex-Token $http_x_plex_token;
proxy_set_header X-Plex-Version $http_x_plex_version;
proxy_set_header X-Plex-Nocache $http_x_plex_nocache;
proxy_set_header X-Plex-Provides $http_x_plex_provides;
proxy_set_header X-Plex-Device-Vendor $http_x_plex_device_vendor;
proxy_set_header X-Plex-Model $http_x_plex_model;
2021-08-07 12:38:18 +01:00
2023-06-26 19:49:52 +01:00
# Buffering off send to the client as soon as the data is received from Plex.
proxy_redirect off;
proxy_buffering off;
2021-08-07 12:38:18 +01:00
2023-06-26 19:49:52 +01:00
add_header 'Content-Security-Policy' 'upgrade-insecure-requests';
'';
};
2021-08-07 12:38:18 +01:00
};
};
2021-11-25 11:42:32 +00:00
users.groups.media.members = [ "plex" ];
2021-08-07 12:38:18 +01:00
}