1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to view IP of upstream server when load balancing?

Discussion in 'Nginx' started by AppleBag, Mar 13, 2022.

  1. #1
    I've added a second plex server to another machine on my local lan so if the first one goes down for any reason it'll load the second one as a backup. Now, when viewing the logs I want to be able to see which IP it was sent to. Here's what I have so far:

    The upstream and log code in plex.subdomain.conf:

    
    upstream plex-resolver {
        server 192.168.0.195:32400;
        server 192.168.0.194:32400 backup;
    }
    
    # TODO: $proxy_host isnt really what I want;  I want to see exactly which pms server it went to.
    log_format plex_access '[$time_local] $remote_addr - $host -> $upstream_addr (SentTo: $proxy_host): $request $status upstream_response_time $upstream_response_time msec $msec request_time $request_time tst: $upstream_http_server';
    
    # Send Plex-only traffic to it's own log for easier viewing.
    map $host $pms {
        default 0;
        ~*^plex 1;
    }
    
    access_log /config/log/nginx/plex_access.log plex_access if=$pms;
    
    Code (markup):
    and the code sending to the resolver:

    
    set $upstream_app plex-resolver;
    set $upstream_proto https;
    proxy_pass $upstream_proto://$upstream_app;
    
    Code (markup):
    I want the "SentTo:" to always show me the exact IP of the endpoint it was sent to, but it just shows the name of the upstream block instead:

    
    [10/Mar/2022:23:32:20 -0600] 10.0.0.2 - plex.<redacted>.rocks -> 192.168.0.194:32400 (SentTo: plex-resolver): GET /?X-Plex-Token=<redacted> HTTP/2.0 200 upstream_response_time 0.000 msec 1646976740.193 request_time 0.008
    [10/Mar/2022:23:32:23 -0600] 10.0.0.2 - plex.<redacted>.rocks -> - (SentTo: -): GET /?X-Plex-Token=<redacted> HTTP/1.1 301 upstream_response_time - msec 1646976743.577 request_time 0.000 -
    [10/Mar/2022:23:32:23 -0600] 10.0.0.2 - plex.<redacted>.rocks -> 192.168.0.194:32400 (SentTo: plex-resolver): GET /?X-Plex-Token=<redacted> HTTP/2.0 200 upstream_response_time 0.010 msec 1646976743.747 request_time 0.009
    [10/Mar/2022:23:32:24 -0600] 10.0.0.2 - plex.<redacted>.rocks -> - (SentTo: -): GET /library/sections?X-Plex-Token=<redacted> HTTP/1.1 301 upstream_response_time - msec 1646976744.596 request_time 0.000 -
    [10/Mar/2022:23:32:24 -0600] 10.0.0.2 - plex.<redacted>.rocks -> 192.168.0.194:32400 (SentTo: plex-resolver): GET /library/sections?X-Plex-Token=<redacted> HTTP/2.0 200 upstream_response_time 0.000 msec 1646976744.752 request_time 0.006
    [10/Mar/2022:23:32:34 -0600] 10.0.0.2 - plex.<redacted>.rocks -> 192.168.0.195:32400, 192.168.0.194:32400 (SentTo: plex-resolver): GET /?X-Plex-Token=<redacted> HTTP/2.0 200 upstream_response_time 21.040, 0.010 msec 1646976754.110 request_time 21.052
    [11/Mar/2022:00:00:55 -0600] 10.0.0.2 - plex.<redacted>.rocks -> 192.168.0.195:32400, 192.168.0.194:32400 (SentTo: plex-resolver): GET /library/sections HTTP/2.0 200 upstream_response_time 21.040, 0.010 msec 1646978455.131 request_time 21.047
    
    Code (markup):
    Does anyone know how to do what I'm looking for?
     
    AppleBag, Mar 13, 2022 IP