To get Plex working on my old Apple TV 3, I had to setup a PlexConnect server that bridges the Apple TV 3 to the Plex Media Server. Previously I discussed about hosting the PlexConnect server on a virtual machine (VM) because the host that PlexConnect is running on must be listening to port 80 and 443. Having a virtual machine is a big nuisance, because the VM may not be up and running. I even try to host PlexConnect on a dedicate Raspberry Pi so that I can leave it on, but that proved to be too slow.
I do have a Network Attached Storage (NAS) server so it will be ideal to run PlexConnect on that, but the NAS server is running Apache 2 which is already using port 80 and 443. Eureka! How about running a reverse proxy that points to an instance of PlexConnect running on the NAS that is running on a separate port. A quick Google search for the term “PlexConnect and Apache 2” found this page on GitHub. The article turned out to be extremely helpful.
I downloaded PlexConnect as before and created the certificates.
cd /home/kang wget https://github.com/iBaa/PlexConnect/archive/V0.6.tar.gz tar zxvf V0.6.tar.gz mv PlexConnect-0.6 PlexConnect rm V0.6.tar.gz cd PlexConnect/assets/certificates openssl req -new -nodes -newkey rsa:2048 -out trailers.pem -keyout trailers.key -x509 -days 365 -subj "/C=US/CN=trailers.apple.com" openssl x509 -in trailers.pem -outform der -out trailers.cer && cat trailers.key >> trailers.pem
I then have to tell PlexConnect the following:
- Do not enable DNS since we already have a DNS server running;
- Do not enable automatic IP detection because it will get the wrong VPN client IP, instead I hard coded the
192.168.168.198
IP; - Disable SSL server because this will be handled by Apache 2;
- Change the port number from
80
to18080
The final Settings.cfg
configuration file looks like this with the changed values highlighted in bold:
[PlexConnect] enable_plexgdm = True ip_pms = 192.168.178.10 port_pms = 32400 enable_dnsserver = False port_dnsserver = 53 ip_dnsmaster = 8.8.8.8 prevent_atv_update = True intercept_atv_icon = True icon = movie-trailers enable_plexconnect_autodetect = False ip_plexconnect = 192.168.168.198 hosttointercept = trailers.apple.com port_webserver = 18080 enable_webserver_ssl = False port_ssl = 18443 certfile = ./assets/certificates/trailers.pem allow_gzip_atv = False allow_gzip_pmslocal = False allow_gzip_pmsremote = True loglevel = Normal logpath = .
I had to configure my firewall’s local DNS to resolve trailers.apple.com
to my NAS server, which is 192.168.168.198
. This was pretty simple on my UniFi Universal Secure Gateway (USG).
The Apache 2 configuration files needed to be setup with the reverse proxy for both port 80
and 443
. To do this I added the following VirtualHost
settings.
<VirtualHost *:443> ServerName trailers.apple.com SSLEngine on SSLProxyEngine on SSLCertificateFile "/home/kang/PlexConnect/assets/certificates/trailers.pem" SSLCertificateKeyFile "/home/kang/PlexConnect/assets/certificates/trailers.key" <Proxy *> Require ip 192.168.168.0/255.255.255.0 </Proxy> RequestHeader set User-Agent AppleTV ProxyRequests Off ProxyPass / http://avs.localdomain:18080/ nocanon ProxyPassReverse / http://avs.localdomain:18080/ </VirtualHost> <VirtualHost *:80> ServerName trailers.apple.com SSLEngine off <Proxy *> Require ip 192.168.168.0/255.255.255.0 </Proxy> RequestHeader set User-Agent AppleTV ProxyRequests Off ProxyPass / http://avs.localdomain:18080/ nocanon ProxyPassReverse / http://avs.localdomain:18080/ </VirtualHost>
I also needed to enable the headers
module.
sudo a2enmod headers
We then needed to create a new systemctl
service for PlexConnect. I had to create a plexconnect.service
file in /etc/systemd/system
with the following contents.
[Unit] Description=Plexconnect After=plexmediaserver.service [Service] Type=simple ExecStart=/usr/bin/python /home/kang/PlexConnect/PlexConnect.py User=root Group=root Restart=on-failure RestartSec=15 StartLimitInterval=10s StartLimitBurst=3 [Install] WantedBy=multi-user.target
The final steps are:
- Check the Apache configuration file
- Restart Apache
- Start PlexConnect
sudo apache2ctl configtest sudo systemctl restart apache2 sudo systemctl start plexconnect.service
Went to the Apple TV 3, and reconfigure the DNS to auto
, removed the old profile and re-add http://trailers.apple.com/trailers.cer
as the new profile. I discussed in my previous blog.
After signing into my Plex account, and testing various Plex media sources with the Trailers app, as well as trying out YouTube and the Prime Video app, everything is good! The VM is no longer required and we declare victory!