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

2

There are 2 best solutions below

28
patriotyk On BEST ANSWER

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;
8
Stephen Dunne On

As per your questions the error message says:

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

In your nginx config you are explicitly passing the $host variable to this header.

proxy_set_header Referer $host;

From the Nginx docs here the host variable will hold:

$host

in this order of precedence: host name from the request line, or host name from the “Host” request header field, or the server name matching a request

It would appear that the value being passed here does not match your configured domain names in the plex config.

You could investigate the value by adding a location block and browsing to it.

    location = /showhost {
        default_type text/html;
        return 200 "Host: $host" ;
    }

If this variable is not set to an appropriate value it might be to worth trying a different var for example $host_name

You could just explicitly pass localhost or one of your configured server names as the header value.