NGINX反向代理背后的Plex:“请求进来,头Host中有无法识别的域/ IP 'plex.mydomain.com';视为非本地

abithluo  于 2023-04-20  发布在  Nginx
关注(0)|答案(2)|浏览(248)

我正在运行 Plex Media Server的最新版本:版本1.31.2.6810。在我的Plex服务器的 * 网络 * 设置下,我指定了我的自定义域名:
自定义服务器访问URL:https://plex.mydomain.com,https://mediaplex.mydomain.com
然而,在Plex的控制台日志中,我不断收到以下消息;我不希望我的plex客户端被视为 '非本地'

“请求在头Referer中带有无法识别的域/ IP 'plex.mydomain.com';视为非本地”

我试着使用这个Gist Github post和这个Gist Github post2的NGINX配置;这是专门用来处理这个问题(至少对于旧版本的Plex服务器).然而,它没有任何区别.我在这个配置中缺少什么?
PS:我在Plex的网络设置下启用了以下设置。我不确定这是否会导致我看到的问题。
将️WAN IP视为LAN带宽

nginx.conf

server {
        listen 443 ssl http2; 
        listen [::]:443 ssl http2;
        ssl_certificate     ./ssl/fullchain.cer;
        ssl_certificate_key ./ssl/cert.key;
        ssl_prefer_server_ciphers on;
        server_name  plex.mydomain.com mediaplex.mydomain.com;
        client_max_body_size 0;
        set $plex http://127.0.0.1:32400;
        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]\.";

        # Forward real ip and host to Plex
        proxy_set_header Host $host;
        proxy_set_header Referer $host;
        proxy_set_header Origin $host;
        proxy_set_header X-Real-IP $remote_addr;
        #When using ngx_http_realip_module change $proxy_add_x_forwarded_for to '$http_x_forwarded_for,$realip_remote_addr'
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        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;
        proxy_set_header Cookie $http_cookie;
        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-Version $http_sec_websocket_version;

        # Websockets
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";

        # Buffering off send to the client as soon as the data is received from Plex.
        proxy_redirect off;
        proxy_buffering off;

        location / {
            # if a request to / comes in, 301 redirect to the main plex page.
            # but only if it doesn't contain the X-Plex-Device-Name header
            # this fixes a bug where you get permission issues when accessing the web dashboard
            # Redirect if not an options request.
            if ($request_method != OPTIONS ) {
                    set $test A;
            }
            if ($http_x_plex_device_name = '') {
                    set $test "${test}B";
            }
            if ($arg_X-Plex-Device-Name = '') {
                    set $test "${test}C";
            }
            if ($test = ABC) {
                    rewrite ^/$ https://$http_host/web/index.html;
            }
            proxy_pass $plex;
        }
}
fruv7luv

fruv7luv1#

根据您的问题,错误消息显示:
“请求进来与无法识别的域/ IP 'plex.mydomain.com'在头引用;视为非本地”
在你的nginx配置中,你显式地将$host变量传递给这个头文件。

proxy_set_header Referer $host;

从Nginx文档here中,主机变量将保存:

  • $主机 *
  • 按此优先次序:请求行中的主机名,或“主机”请求标头字段中的主机名,或与请求匹配的服务器名 *

这里传递的值似乎与您在丛配置中配置的域名不匹配。
您可以通过添加位置块并浏览它来调查该值。

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

如果此变量未设置为适当的值,则可能值得尝试其他变量,例如$host_name
您可以只显式传递localhost或一个已配置的服务器名称作为头值。

ejk8hzay

ejk8hzay2#

就像你说的192.168.1.2很适合你。你可以把它传递给plex。所以在你的nginx配置文件中替换

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

其中:

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;

相关问题