{"id":835,"date":"2019-12-07T13:56:43","date_gmt":"2019-12-07T18:56:43","guid":{"rendered":"https:\/\/blog.lufamily.ca\/kang\/?p=835"},"modified":"2019-12-07T13:56:44","modified_gmt":"2019-12-07T18:56:44","slug":"plexconnect-with-apache-2","status":"publish","type":"post","link":"https:\/\/blog.lufamily.ca\/kang\/2019\/12\/07\/plexconnect-with-apache-2\/","title":{"rendered":"PlexConnect with Apache 2"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>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 &#8220;PlexConnect and Apache 2&#8221; found this <a rel=\"noreferrer noopener\" aria-label=\"page (opens in a new tab)\" href=\"https:\/\/github.com\/iBaa\/PlexConnect\/issues\/441\" target=\"_blank\">page<\/a> on GitHub. The article turned out to be extremely helpful.<\/p>\n\n\n\n<p>I downloaded PlexConnect as before and created the certificates.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">cd \/home\/kang\n\nwget https:\/\/github.com\/iBaa\/PlexConnect\/archive\/V0.6.tar.gz\n\ntar zxvf V0.6.tar.gz\u00a0\n\nmv PlexConnect-0.6 PlexConnect\n\nrm V0.6.tar.gz\n\ncd PlexConnect\/assets\/certificates\n\nopenssl req -new -nodes -newkey rsa:2048 -out trailers.pem -keyout trailers.key -x509 -days 365 -subj \"\/C=US\/CN=trailers.apple.com\"\n\nopenssl x509 -in trailers.pem -outform der -out trailers.cer &amp;&amp; cat trailers.key >> trailers.pem<\/pre>\n\n\n\n<p>I then have to tell PlexConnect the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Do not enable DNS since we already have a DNS server running;<\/li><li>Do not enable automatic IP detection because it will get the wrong VPN client IP, instead I hard coded the <code>192.168.168.198<\/code> IP;<\/li><li>Disable SSL server because this will be handled by Apache 2;<\/li><li>Change the port number from <code>80<\/code> to <code>18080<\/code><\/li><\/ul>\n\n\n\n<p>The final <code>Settings.cfg<\/code> configuration file looks like this with the changed values highlighted in bold:<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">[PlexConnect]\nenable_plexgdm = True\nip_pms = 192.168.178.10\nport_pms = 32400\nenable_dnsserver = <strong>False<\/strong>\nport_dnsserver = 53\nip_dnsmaster = 8.8.8.8\nprevent_atv_update = True\nintercept_atv_icon = True\nicon = movie-trailers\nenable_plexconnect_autodetect = <strong>False<\/strong>\nip_plexconnect = <strong>192.168.168.198<\/strong>\nhosttointercept = trailers.apple.com\nport_webserver = <strong>18080<\/strong>\nenable_webserver_ssl = <strong>False<\/strong>\nport_ssl = <strong>18443<\/strong>\ncertfile = .\/assets\/certificates\/trailers.pem\nallow_gzip_atv = False\nallow_gzip_pmslocal = False\nallow_gzip_pmsremote = True\nloglevel = Normal\nlogpath = .\n<\/pre>\n<\/div><\/div>\n\n\n\n<p>I had to configure my firewall&#8217;s local DNS to resolve <code>trailers.apple.com<\/code> to my NAS server, which is <code>192.168.168.198<\/code>. This was pretty simple on my UniFi Universal Secure Gateway (USG).<\/p>\n\n\n\n<p>The Apache 2 configuration files needed to be setup with the reverse proxy for both port <code>80<\/code> and <code>443<\/code>. To do this I added the following <code>VirtualHost<\/code> settings.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<pre class=\"wp-block-preformatted\">&lt;VirtualHost *:443&gt;\n        ServerName trailers.apple.com\n\n        SSLEngine on\n        SSLProxyEngine on\n        SSLCertificateFile \"\/home\/kang\/PlexConnect\/assets\/certificates\/trailers.pem\"\n        SSLCertificateKeyFile \"\/home\/kang\/PlexConnect\/assets\/certificates\/trailers.key\"\n\n\t&lt;Proxy *&gt;\n\t\tRequire ip 192.168.168.0\/255.255.255.0\n\t&lt;\/Proxy&gt;\n\n        RequestHeader set User-Agent AppleTV\n        ProxyRequests Off\n        ProxyPass \/ http:\/\/avs.localdomain:18080\/ nocanon\n        ProxyPassReverse \/ http:\/\/avs.localdomain:18080\/\n&lt;\/VirtualHost&gt;\n&lt;VirtualHost *:80&gt;\n        ServerName trailers.apple.com\n        SSLEngine off\n\n\t&lt;Proxy *&gt;\n\t\tRequire ip 192.168.168.0\/255.255.255.0\n\t&lt;\/Proxy&gt;\n\n        RequestHeader set User-Agent AppleTV\n        ProxyRequests Off\n        ProxyPass \/ http:\/\/avs.localdomain:18080\/ nocanon\n        ProxyPassReverse \/ http:\/\/avs.localdomain:18080\/\n&lt;\/VirtualHost&gt;\n<\/pre>\n<\/div><\/div>\n\n\n\n<p>I also needed to enable the <code>headers<\/code> module.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo a2enmod headers<\/pre>\n\n\n\n<p>We then needed to create a new <code>systemctl<\/code> service for PlexConnect. I had to create a <code>plexconnect.service<\/code> file in <code>\/etc\/systemd\/system<\/code> with the following contents.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">[Unit]\n Description=Plexconnect\n After=plexmediaserver.service\n \n [Service]\n Type=simple\n ExecStart=\/usr\/bin\/python \/home\/kang\/PlexConnect\/PlexConnect.py\n User=root\n Group=root\n Restart=on-failure\n RestartSec=15\n StartLimitInterval=10s\n StartLimitBurst=3\n \n [Install]\n WantedBy=multi-user.target\n <\/pre>\n\n\n\n<p>The final steps are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Check the Apache configuration file<\/li><li>Restart Apache<\/li><li>Start PlexConnect<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo apache2ctl configtest\n\nsudo systemctl restart apache2\n\nsudo systemctl start plexconnect.service<\/pre>\n\n\n\n<p>Went to the Apple TV 3, and reconfigure the DNS to <code><strong>auto<\/strong><\/code>, removed the old profile and re-add <code>http:\/\/trailers.apple.com\/trailers.cer<\/code> as the new profile. I discussed in my previous <a href=\"https:\/\/blog.lufamily.ca\/kang\/2019\/12\/06\/plex-on-apple-tv-3\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"blog (opens in a new tab)\">blog<\/a>.<\/p>\n\n\n\n<p>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!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <a href=\"https:\/\/blog.lufamily.ca\/kang\/2019\/12\/07\/plexconnect-with-apache-2\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;PlexConnect with Apache 2&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[107,105,106],"class_list":["post-835","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-apache","tag-apple-tv","tag-plex"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7V6i8-dt","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/posts\/835","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/comments?post=835"}],"version-history":[{"count":6,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/posts\/835\/revisions"}],"predecessor-version":[{"id":841,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/posts\/835\/revisions\/841"}],"wp:attachment":[{"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/media?parent=835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/categories?post=835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.lufamily.ca\/kang\/wp-json\/wp\/v2\/tags?post=835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}