Using PlexConnect behind nginx

Hi!

 

I'm going to post my current setup, as I couldn't find anything regarding nginx here and I guess it might be useful for some people. There's probably some space for improvements, so feedback is much appreciated! I'm using Ubuntu 14.04 64bit, but that shouldn't really matter.

 

This is the nginx configuration. It's located at /etc/nginx/sites-available/plexconnect. 192.168.0.42 is the IP of my home server where plexmediaserver, plexconnect & nginx are running. Using 127.0.0.1 is not working here, as PlexConnect only listens on 192.168.0.42. 8080 is the http port of plexconnect.

upstream plexconnect {
  server 192.168.0.42:8080;
}

server {
listen 80;
server_name trailers.apple.com;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass  http://plexconnect;

}
}

server {
listen 443;
server_name trailers.apple.com;

ssl_certificate /path/to/plexconnect/assets/certificates/trailers.pem;
ssl_certificate_key /path/to/plexconnect/assets/certificates/trailers.key;

ssl on;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass  http://plexconnect;

}
}

This is the configuration of PlexConnect. Here it's important to change the port_webserver variable. It should match the value in the nginx config (8080 here). enable_webserver_ssl is disabled, SSL is handled by nginx.

[PlexConnect]
enable_plexgdm = False
ip_pms = 192.168.0.42
port_pms = 32400
enable_dnsserver = True
port_dnsserver = 53
ip_dnsmaster = 8.8.8.8
prevent_atv_update = True
enable_plexconnect_autodetect = True
ip_plexconnect = 0.0.0.0
hosttointercept = trailers.apple.com
port_webserver = 8080
enable_webserver_ssl = False
port_ssl = 4443
certfile = ./assets/certificates/trailers.pem
loglevel = Normal
logpath = .

Hey,

thanks for your config. It worked perfectly for me!

Note that you also have to copy the trailers.key file to the assets/certificates directory (which is not needed for the other setup).

/Emil

I had installed PlecConnect on my debian (OpenMediaVault). I use nginx for different Sites (omv, owncloud). Port 80 and 443 are used. When i use your config file I can not restart nginx.

The ports are already in use:

nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

When I change the ports to 180 und 1443 in the nginx config file. Then i can start nging, but i can't start ./PlexConnect.py, because the ports are already in use from nginx.

@elmero

Did you find an solution?

I'm also using openmediavault and get also the same error.

BR Robert

@ Heady

If i go an deactivate the PlexConnect SSL by setting False it is not working.

But if i'm going to use Treu it works.

@elmero

If you set the omv gui to an other port it is working.

@elmero

 use the ipv6 format when entering in the listen directive. 

upstream plexconnect {
  server 192.168.1.10:8080;
}

server {
listen [::]:80;
server_name trailers.apple.com;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass  http://plexconnect;

}
}

server {
listen [::]:443;
server_name trailers.apple.com;

ssl_certificate /opt/PlexConnect/assets/certificates/trailers.pem;
ssl_certificate_key /opt/PlexConnect/assets/certificates/trailers.key;

ssl on;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass  http://plexconnect;

}
}

 Working for me!  no need to change the OMV port.

Hi,

I'm trying to set up my raspberry pi as Plex Server. At the current step I experience problems in getting my AppleTV3 to recognize my Plex Server via "Trailers". Probably due a collision of Nginx and PlexConnect as described by some of you above. Here are the symptoms:

  • My Plex Server is running. I can access the web interface via my web browser.
  • My ATV3 has internet connection and can access the apple movie, series & other databases.
  • However when I navigate to "Trailers" ATV3 complains that Trailers can't be accessed!
  • Nginx is running by default on the installation and using port 80 and 443.

Two further notes:

  • My old Plex Server is running on my windows pc and Apple TV can communicate without problems. 
  • As long as I use the windows PC as DNS server for ATV3 with PlexConnect running on the windows PC, my ATV recognizes both libraries in "Trailers": The old Windows PC based library and the new raspberry library.

Here is what I did until now:

  • Setup my raspberry using one of the images provided by HTPC Guides. This is a minimal Debian installation already including the plex media server installed as well as nginx. But by default no PlexConnect is installed.
  • Install PlexConnect and tried to get the connection running and tried to follow the hints mentioned above.
  • I created the certificates and the corresponding ATV3 profile.

Below are copies of my files (my raspberry within the network is 192.168.2.110).

/etc/nginx/sites-available/plexconnect

upstream plexconnect {
  server 192.168.2.110:8080;
}

server {
listen [::]:80;
server_name trailers.apple.com;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass  http://plexconnect;

}
}

server {
listen [::]:443;
server_name trailers.apple.com;

ssl_certificate /opt/PlexConnect/assets/certificates/trailers.pem;
ssl_certificate_key /opt/PlexConnect/assets/certificates/trailers.key;

ssl on;

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass  http://plexconnect;

}
}

/etc/nginx/sites-available/trailers.apple.com

server {
        listen 80;
        server_name 192.168.2.110;
    root /var/www/trailers.apple.com/public_html;
    index index.html index.htm;

}

/opt/PlexConnect/Settings.cfg

[PlexConnect]
enable_plexgdm = False
ip_pms = 192.168.2.110
port_pms = 32400
enable_dnsserver = True
port_dnsserver = 53
ip_dnsmaster = 192.168.2.1
prevent_atv_update = True
enable_plexconnect_autodetect = True
ip_plexconnect = 0.0.0.0
hosttointercept = trailers.apple.com
port_webserver = 8080
enable_webserver_ssl = False
port_ssl = 443
certfile = ./assets/certificates/trailers.pem
allow_gzip_atv = False
allow_gzip_pmslocal = False
allow_gzip_pmsremote = True
loglevel = Normal
logpath = .

/opt/PlexConnect/Settings.py

    # load/save config
    def loadSettings(self):
        dprint(__name__, 1, "load settings")
        self.cfg.read(self.getSettingsFile())
def saveSettings(self):
    dprint(__name__, 1, "save settings")
    f = open(self.getSettingsFile(), 'wb')
    self.cfg.write(f)
    f.close()

def getSettingsFile(self):
    return sys.path[0] + sep + "Settings.cfg"

def checkSection(self):
    modify = False
    # check for existing section
    if not self.cfg.has_section(self.section):
        modify = True
        self.cfg.add_section(self.section)
        dprint(__name__, 0, "add section {0}", self.section)
    
    for (opt, (dflt, vldt)) in g_settings:
        setting = self.cfg.get(self.section, opt)
        if setting=='\0':
            # check settings - add if new
            modify = True
            self.cfg.set(self.section, opt, dflt)
            dprint(__name__, 0, "add setting {0}={1}", opt, dflt)
        
        elif not re.search('\A'+vldt+'\Z', setting):
            # check settings - default if unknown
            modify = True
            self.cfg.set(self.section, opt, dflt)
            dprint(__name__, 0, "bad setting {0}={1} - set default {2}", opt, setting, dflt)
    
    # save if changed
    if modify:
        self.saveSettings()



# access/modify PlexConnect settings
def getSetting(self, option):
    dprint(__name__, 1, "getsetting {0}={1}", option, self.cfg.get(self.section, option))
    return self.cfg.get(self.section, option)

if name==“main”:
Settings = CSettings()

option = 'enable_plexgdm'
print Settings.getSetting(option)

option = 'enable_dnsserver'
print Settings.getSetting(option)

del Settings

(END)

And a copy of the used ports:

Plex      2267     plex   54u  IPv4   8597      0t0  TCP *:32400 (LISTEN)
Plex      2267     plex   55u  IPv4   8598      0t0  TCP *:32401 (LISTEN)
Plex      2267     plex   65u  IPv4   8678      0t0  UDP *:32414 
Plex      2267     plex   71u  IPv4   9374      0t0  UDP *:32410 
Plex      2267     plex   72u  IPv4   8680      0t0  UDP *:32413 
Plex      2267     plex   74u  IPv4   8681      0t0  UDP localhost:55759 
Plex      2267     plex   75u  IPv4   8682      0t0  UDP 192.168.2.110:59392 
Plex      2267     plex   76u  IPv4   8683      0t0  UDP localhost:54731 
Plex      2267     plex   77u  IPv4   8684      0t0  UDP 192.168.2.110:46900
Plex      2528     plex   12u  IPv4   8689      0t0  UDP *:1900 
Plex      2528     plex   15u  IPv4   8692      0t0  TCP *:1664 (LISTEN)
Plex      2528     plex   18u  IPv4   8696      0t0  UDP *:13169 
Plex      2528     plex   21u  IPv4   8699      0t0  TCP *:32469 (LISTEN)
Plex      2528     plex   24u  IPv4   8702      0t0  UDP *:51866 
Plex      2528     plex   27u  IPv4   8705      0t0  UDP *:52843 
Plex      2528     plex   67u  IPv4   8679      0t0  TCP localhost:34420->localhost:54123 (CLOSE_WAIT)
nginx     2294     root    6u  IPv4   9300      0t0  TCP *:80 (LISTEN)
nginx     2294     root    7u  IPv6   9301      0t0  TCP *:80 (LISTEN)
nginx     2294     root    8u  IPv4   9302      0t0  TCP *:443 (LISTEN)
nginx     2295 www-data    6u  IPv4   9300      0t0  TCP *:80 (LISTEN)
nginx     2295 www-data    7u  IPv6   9301      0t0  TCP *:80 (LISTEN)
nginx     2295 www-data    8u  IPv4   9302      0t0  TCP *:443 (LISTEN)
nginx     2296 www-data    6u  IPv4   9300      0t0  TCP *:80 (LISTEN)
nginx     2296 www-data    7u  IPv6   9301      0t0  TCP *:80 (LISTEN)
nginx     2296 www-data    8u  IPv4   9302      0t0  TCP *:443 (LISTEN)
nginx     2297 www-data    6u  IPv4   9300      0t0  TCP *:80 (LISTEN)
nginx     2297 www-data    7u  IPv6   9301      0t0  TCP *:80 (LISTEN)
nginx     2297 www-data    8u  IPv4   9302      0t0  TCP *:443 (LISTEN)
nginx     2298 www-data    6u  IPv4   9300      0t0  TCP *:80 (LISTEN)
nginx     2298 www-data    7u  IPv6   9301      0t0  TCP *:80 (LISTEN)
nginx     2298 www-data    8u  IPv4   9302      0t0  TCP *:443 (LISTEN)

Plexconnect log from your new setup?

22:10:42 PlexConnect: started: 22:10:42
22:10:42 PlexConnect: Version: 0.5-dev-020615
22:10:42 PlexConnect: Python: 2.7.9 (default, Mar  8 2015, 00:52:26) 
[GCC 4.9.2]
22:10:42 PlexConnect: Host OS: linux2
22:10:42 PlexConnect: PILBackgrounds: Is PIL installed? True
22:10:42 PlexConnect: IP_self: 192.168.2.110
22:10:42 DNSServer: started: 22:10:42
22:10:42 DNSServer: ***
22:10:42 DNSServer: DNSServer: Serving DNS on 192.168.2.110 port 53.
22:10:42 DNSServer: ***
22:10:42 WebServer: started: 22:10:42
22:10:42 WebServer: ***
22:10:42 WebServer: WebServer: Serving HTTP on 192.168.2.110 port 8080.
22:10:42 WebServer: ***
/opt/PlexConnect/PlexConnect.log (END)

That shows no activity. Any firewall that might be blocking?

No, not unless the debian (minibian?) installation has one configured by standard. But that would not make sense.

I configured my ATV3 such that it uses the raspberry as DNS server. The ATV CAN browse all the other libraries such as the apple movie (store), Netflix, youtube and so on. So there HAS to be communication between ATV and the raspberry.

I can remember that I saw some log file where connections were registered. I just can't remember where. I'm quite sure (though I won't vow) that it wasn't the plexconnect log.

PS: Now I remember when and where I saw the communication!

When I start PlexConnect via the python script (opt/PlexConnect/PlexConnect.py) I can see the log messages directly in my shell because they are not redirected into the log file.

In THIS case I can see all the communication between ATV and the raspberry:

pi@raspberrypi:~$ sudo /opt/PlexConnect/PlexConnect.py 
21:08:19 PlexConnect: ***
21:08:19 PlexConnect: PlexConnect
21:08:19 PlexConnect: Press CTRL-C to shut down.
21:08:19 PlexConnect: ***
21:08:19 PlexConnect: started: 21:08:19
21:08:19 PlexConnect: Version: 0.5-dev-020615
21:08:19 PlexConnect: Python: 2.7.9 (default, Mar  8 2015, 00:52:26) 
[GCC 4.9.2]
21:08:19 PlexConnect: Host OS: linux2
21:08:19 PlexConnect: PILBackgrounds: Is PIL installed? True
21:08:19 PlexConnect: IP_self: 192.168.2.110
21:08:19 DNSServer: started: 21:08:19
21:08:19 DNSServer: ***
21:08:19 DNSServer: DNSServer: Serving DNS on 192.168.2.110 port 53.
21:08:19 DNSServer: intercept: ['trailers.apple.com'] => 192.168.2.110
21:08:19 DNSServer: restrain: ['mesu.apple.com', 'appldnld.apple.com', 'appldnld.apple.com.edgesuite.net'] => 127.0.0.1
21:08:19 DNSServer: forward other to higher level DNS: 192.168.2.1
21:08:19 DNSServer: ***
21:08:19 WebServer: started: 21:08:19
21:08:19 WebServer: ***
21:08:19 WebServer: WebServer: Serving HTTP on 192.168.2.110 port 8080.
21:08:19 WebServer: ***
21:08:33 DNSServer: DNS request received!
21:08:33 DNSServer: Source: ('192.168.2.100', 52350)
21:08:33 DNSServer: Domain: youtube-ui.l.google.com
21:08:33 DNSServer: ***forward request
21:08:33 DNSServer: -> DNS response from higher level
21:08:33 DNSServer: DNS request received!
21:08:33 DNSServer: Source: ('192.168.2.100', 63738)
21:08:33 DNSServer: Domain: youtube-ui.l.google.com
21:08:33 DNSServer: ***forward request
21:08:33 DNSServer: -> DNS response from higher level
21:08:35 DNSServer: DNS request received!
21:08:35 DNSServer: Source: ('192.168.2.100', 64808)
21:08:35 DNSServer: Domain: s.ytimg.com
21:08:35 DNSServer: ***forward request
21:08:35 DNSServer: -> DNS response from higher level
21:08:35 DNSServer: DNS request received!
21:08:35 DNSServer: Source: ('192.168.2.100', 53930)
21:08:35 DNSServer: Domain: s.ytimg.com
21:08:35 DNSServer: ***forward request
21:08:35 DNSServer: -> DNS response from higher level
21:08:36 DNSServer: DNS request received!
21:08:36 DNSServer: Source: ('192.168.2.100', 56723)
21:08:36 DNSServer: Domain: csi.gstatic.com
21:08:36 DNSServer: ***forward request
21:08:36 DNSServer: -> DNS response from higher level
21:08:36 DNSServer: DNS request received!
21:08:36 DNSServer: Source: ('192.168.2.100', 64856)
21:08:36 DNSServer: Domain: csi.gstatic.com
21:08:36 DNSServer: ***forward request
21:08:36 DNSServer: -> DNS response from higher level
21:08:36 DNSServer: DNS request received!
21:08:36 DNSServer: Source: ('192.168.2.100', 56241)
21:08:36 DNSServer: Domain: ytimg.l.google.com
21:08:36 DNSServer: ***forward request
21:08:36 DNSServer: -> DNS response from higher level
21:08:36 DNSServer: DNS request received!
21:08:36 DNSServer: Source: ('192.168.2.100', 52047)
21:08:36 DNSServer: Domain: ytimg.l.google.com
21:08:36 DNSServer: ***forward request
21:08:36 DNSServer: -> DNS response from higher level

This is the "trailers" specific communication:

21:18:27 DNSServer: DNS request received!
21:18:27 DNSServer: Source: ('192.168.2.100', 56521)
21:18:27 DNSServer: Domain: trailers.apple.com
21:18:27 DNSServer: ***intercept request
21:18:27 DNSServer: -> DNS response: 192.168.2.110
21:18:27 DNSServer: DNS request received!
21:18:27 DNSServer: Source: ('192.168.2.100', 51051)
21:18:27 DNSServer: Domain: trailers.apple.com
21:18:27 DNSServer: ***intercept request
21:18:27 DNSServer: -> DNS response: 192.168.2.110
 

And even though: "Trailers is not available".

And this is the content of my "/etc/init.d/plexconnect":

INSTDIR="/opt/PlexConnect"
DAEMON="$INSTDIR/PlexConnect.py"
DAEMON_OPTS="2>&1 >/dev/null"
DAEMON_USER="root"

PIDFILE=/var/run/PlexConnect.pid

test -x “$DAEMON” || exit 5

case $1 in
start)
if [ -e $PIDFILE ]; then
status_of_proc -p $PIDFILE “$DAEMON $DAEMON_OPTS” “$NAME process” && status=“0” || status="$?"
if [ $? = “0” ]; then
log_success_msg “Starting the process $NAME”
exit # Exit
fi
fi
# Start the daemon.
# Start the daemon with the help of start-stop-daemon
# Log the message appropriately
if start-stop-daemon --start --quiet --oknodo --background --make-pidfile --pidfile $PIDFILE --startas $DAEMON -p $PIDFILE – ${DAEMON_OPTS}; then
log_success_msg “Starting the process $NAME”
else
log_failure_msg “Starting the process $NAME”
fi
;;
stop)

            # Stop the daemon.
            if [ -e $PIDFILE ]; then
                    status_of_proc -p $PIDFILE "$DAEMON DAEMON_OPTS" "Stoppping the $NAME process" && status="0" || status="$?"
                    if [ "$?" = 0 ]; then
                            start-stop-daemon --stop --signal 2 --quiet --oknodo --pidfile $PIDFILE && /bin/rm $PIDFILE
                            log_success_msg ""Stopping the $NAME process""
                    fi
            else
                    log_failure_msg "$NAME process is not running"
            fi
            ;;
    restart)
            # Restart the daemon.
            $0 stop && sleep 2 && $0 start
            ;;
    status)
            # Check the status of the process.
            if [ -e $PIDFILE ]; then
                    status_of_proc -p $PIDFILE "$DAEMON $DAEMON_OPTS" "$NAME process" && exit 0 || exit $?
                    log_success_msg "$NAME process is running"
            else
                    log_failure_msg "$NAME process is not running"
            fi
            ;;
    reload)
            $0 restart
            ;;
    *)
            # For invalid arguments, print the usage message.
            echo "Usage: $0 {start|stop|restart|reload|status}"
            exit 2
            ;;

esac

UPDATE:

After reading what feels like gazillions of threads and descriptions on the web I have the feeling that my head is spinning. :unsure:

Yesterday evening I thought I'm missing some step including the reverse proxy. But actually I think this is what I have created above, am I right?

Still, something seems to be missing ... I'm just not sure what.

Thanks so much for your help out there.  :)

Does nobody have an idea which partof the configuration might be missing or might be wrong?  :(

We had a similar problem with DSM6 (a Linux port for Synology NAS), I’m attaching my relevant files used to solve the issue (my devices are in 10.100.10.*):

plexconnect.conf (has to be put in a folder referenced by nginx.conf, in case of DSM6 it is sites-enabled/)

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name trailers.apple.com;

    ssl_certificate /usr/local/plexconnect/etc/certificates/trailers.pem;
    ssl_certificate_key /usr/local/plexconnect/etc/certificates/trailers.key;

    location / {
        proxy_set_header        Host                $host;
        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_intercept_errors  on;
        proxy_http_version      1.1;

        proxy_pass https://10.100.10.100:6443;

    }
}

server {
    listen 80;
    listen [::]:80;

    server_name trailers.apple.com;

    location / {
        proxy_set_header        Host                $host;
        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_intercept_errors  on;
        proxy_http_version      1.1;

        proxy_pass http://10.100.10.100:6080;

    }
}

Settings.cfg (modified to listen ports 6080/6443 instead of 80/443)

[PlexConnect]
enable_plexgdm = True
ip_pms = 0.0.0.0
port_pms = 32400
enable_dnsserver = True
port_dnsserver = 53
ip_dnsmaster = 10.100.10.1
prevent_atv_update = True
enable_plexconnect_autodetect = True
ip_plexconnect = 0.0.0.0
hosttointercept = trailers.apple.com
port_webserver = 6080
enable_webserver_ssl = True
port_ssl = 6443
certfile = /usr/local/plexconnect/etc/certificates/trailers.pem
allow_gzip_atv = False
allow_gzip_pmslocal = False
allow_gzip_pmsremote = True
loglevel = Normal
logpath = /usr/local/plexconnect/var

can anyone enlighten me on the advantages this gives me in contrast to using the standard/non-nginx setup?
thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.