···112112 }
113113 '';
114114 };
115115+116116+ security.acme = {
117117+ acceptTerms = true;
118118+ defaults.email = "noah@packetlost.dev";
119119+ certs."plex.packetlostandfound.us" = {
120120+ group = "nas";
121121+ dnsProvider = "nextdns";
122122+ };
123123+ };
124124+125125+ services.plex = {
126126+ enable = false;
127127+ openFirewall = false; # we proxy this with nginx
128128+ group = "nas";
129129+ user = "noah";
130130+ };
131131+132132+ # Nginx Reverse SSL Proxy
133133+ services.nginx = {
134134+ enable = true;
135135+ # give a name to the virtual host. It also becomes the server name.
136136+ virtualHosts."plex.packetlostandfound.us" = {
137137+ # Since we want a secure connection, we force SSL
138138+ forceSSL = true;
139139+140140+ # http2 can more performant for streaming: https://blog.cloudflare.com/introducing-http2/
141141+ http2 = true;
142142+143143+ # Provide the ssl cert and key for the vhost
144144+ sslCertificate = "/var/lib/acme/plex.packetlostandfound.us/fullchain.pem";
145145+ sslCertificateKey = "/var/lib/acme/plex.packetlostandfound.us/key.pem";
146146+ extraConfig = ''
147147+148148+ #Some players don't reopen a socket and playback stops totally instead of resuming after an extended pause
149149+ send_timeout 100m;
150150+151151+ # Why this is important: https://blog.cloudflare.com/ocsp-stapling-how-cloudflare-just-made-ssl-30/
152152+ ssl_stapling on;
153153+ ssl_stapling_verify on;
154154+155155+ ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
156156+ ssl_prefer_server_ciphers on;
157157+ #Intentionally not hardened for security for player support and encryption video streams has a lot of overhead with something like AES-256-GCM-SHA384.
158158+ ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:ECDHE-RSA-DES-CBC3-SHA:ECDHE-ECDSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
159159+160160+ # Forward real ip and host to Plex
161161+ proxy_set_header X-Real-IP $remote_addr;
162162+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
163163+ proxy_set_header X-Forwarded-Proto $scheme;
164164+ proxy_set_header Host $server_addr;
165165+ proxy_set_header Referer $server_addr;
166166+ proxy_set_header Origin $server_addr;
167167+168168+ # Plex has A LOT of javascript, xml and html. This helps a lot, but if it causes playback issues with devices turn it off.
169169+ gzip on;
170170+ gzip_vary on;
171171+ gzip_min_length 1000;
172172+ gzip_proxied any;
173173+ gzip_types text/plain text/css text/xml application/xml text/javascript application/x-javascript image/svg+xml;
174174+ gzip_disable "MSIE [1-6]\.";
175175+176176+ # Nginx default client_max_body_size is 1MB, which breaks Camera Upload feature from the phones.
177177+ # Increasing the limit fixes the issue. Anyhow, if 4K videos are expected to be uploaded, the size might need to be increased even more
178178+ client_max_body_size 100M;
179179+180180+ # Plex headers
181181+ proxy_set_header X-Plex-Client-Identifier $http_x_plex_client_identifier;
182182+ proxy_set_header X-Plex-Device $http_x_plex_device;
183183+ proxy_set_header X-Plex-Device-Name $http_x_plex_device_name;
184184+ proxy_set_header X-Plex-Platform $http_x_plex_platform;
185185+ proxy_set_header X-Plex-Platform-Version $http_x_plex_platform_version;
186186+ proxy_set_header X-Plex-Product $http_x_plex_product;
187187+ proxy_set_header X-Plex-Token $http_x_plex_token;
188188+ proxy_set_header X-Plex-Version $http_x_plex_version;
189189+ proxy_set_header X-Plex-Nocache $http_x_plex_nocache;
190190+ proxy_set_header X-Plex-Provides $http_x_plex_provides;
191191+ proxy_set_header X-Plex-Device-Vendor $http_x_plex_device_vendor;
192192+ proxy_set_header X-Plex-Model $http_x_plex_model;
193193+194194+ # Websockets
195195+ proxy_http_version 1.1;
196196+ proxy_set_header Upgrade $http_upgrade;
197197+ proxy_set_header Connection "upgrade";
198198+199199+ # Buffering off send to the client as soon as the data is received from Plex.
200200+ proxy_redirect off;
201201+ proxy_buffering off;
202202+ '';
203203+ locations."/" = {
204204+ proxyPass = "http://localhost:32400/";
205205+ };
206206+ };
207207+ };
115208}