nginxreverse-proxynginx-reverse-proxyplex

Plex behind NGINX reverse proxy: "Request came in with unrecognized domain / IP 'plex.mydomain.com' in header Host; treating as non-local


I'm running the latest version of Plex Media Server: Version 1.31.2.6810. Under my Plex server's Network settings, I specified my custom domain names:

Custom server access URLs: https://plex.mydomain.com,https://mediaplex.mydomain.com

However, in Plex's console log, I keep getting the below message; which I don't my plex clients to be treated as 'non-local'

"Request came in with unrecognized domain / IP 'plex.mydomain.com' in header Referer; treating as non-local"


SOLUTION:

Thanks to @patriotyk's answer, I was able to finally make the ultimate nginx plex reverse proxy for custom domain names; assuming the plex network configuration settings are correct. I also posted my gzip settings; to get the fastest possible Plex client performance if you have enough spare CPU horsepower. I also did NOT disable proxy_buffers (like most online Plex nginx config examples) since I'm consistently getting noticeably faster performance with it enabled (in combination with Gzip compression level=9 [max] and gzip_min_length=256). All TV/Movie posters just display at the same time in short bursts.

nginx.conf

http {
    gzip on;
    gzip_vary on;
    gzip_min_length 256;
    gzip_proxied any;
    gzip_comp_level 9;
    gzip_disable "MSIE [1-6]\.";
    gzip_types
        text/css
        text/xml
        text/plain
        text/javascript
        text/cache-manifest
        text/x-cross-domain-policy
        application/javascript
        application/x-javascript
        application/json
        application/manifest+json
        application/xml
        application/xml+rss
        application/xhtml+xml
        application/rss+xml
        application/rdf+xml
        application/atom+xml
        application/atom_xml
        application/geo+json
        application/ttf
        application/x-ttf
        application/x-font-ttf
        application/x-font-otf
        application/x-font-truetype
        application/x-font-opentype
        application/x-web-app-manifest+json
        application/vnd.ms-fontobject
        font/eot
        font/otf
        font/ttf
        font/opentype
        image/svg+xml
        image/x-icon
        image/bmp;
    geo $lan {
        default 0;
        192.168.1.0/24 1;
    }
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    upstream plex_backend {
        server 192.168.1.2:32400;
        keepalive 32;
    }

    server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name plex.mydomain.com mediaplex.mydomain.com;
        client_max_body_size 0;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }
        location / {
            if ($http_x_plex_device_name = '') {
                rewrite ^/$ /web/index.html;
            }
            proxy_pass                          http://plex_backend;
            proxy_set_header Host               192.168.1.2;
            proxy_set_header Referer            https://192.168.1.2:32400;
            proxy_set_header Origin             192.168.1.2;
            proxy_http_version                  1.1;
            proxy_cache_bypass                  $http_upgrade;
            proxy_set_header Upgrade            $http_upgrade;
            proxy_set_header Connection         $connection_upgrade;
            proxy_set_header Accept-Encoding    "";
            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-Host   $host;
            proxy_set_header X-Forwarded-Port   $server_port;
            proxy_set_header Sec-Websocket-Extensions $http_sec_websocket_extensions;
            proxy_set_header Sec-Websocket-Key $http_sec_websocket_key;
            proxy_set_header Sec-Websocket-Protocol $http_sec_websocket_protocol;
            proxy_set_header Sec-Websocket-Version $http_sec_websocket_version;
            proxy_connect_timeout               300;
            proxy_send_timeout                  300;
            proxy_read_timeout                  300;
            proxy_buffers                       512 512k;
            proxy_buffer_size                   512k;
            proxy_busy_buffers_size             512k;
            proxy_redirect off;
        }
    }

}

After using this configuration, instead of getting the below message repeated over and over again in the Plex console log:

"Request came in with unrecognized domain / IP 'plex.mydomain.com' in header Referer; treating as non-local"

I get:

Request: [192.168.1.2:31997 (Allowed Network (Subnet))] GET /status/sessions (14 live) #dc855 Signed-in

enter image description here


Solution

  • As you said that 192.168.1.2 works well for you. You can pass it to the plex. So in your nginx config file replace

    proxy_set_header Host $host;
    proxy_set_header Referer $host;
    proxy_set_header Origin $host;
    

    with:

    proxy_set_header Host 192.168.1.2;
    proxy_set_header Referer https://192.168.1.2:32400;
    proxy_set_header Origin 192.168.1.2;