How to configure Apache in order to proxy Plex (by Adrian P.)
Home
Step 1:
Replace any | with |
RewriteCond %{HTTP_HOST} ^(.*):(.*)$
|
RewriteCond %{HTTP_HOST} ^(.*):(.*)$
RewriteCond %{QUERY_STRING} !X-Plex
RewriteCond %{HTTP:X-Plex-Product} !\w+
|
Step 2:
Replace any | with |
RewriteCond %{HTTP_HOST} !^(.*):(.*)$
|
RewriteCond %{HTTP_HOST} !^(.*):(.*)$
RewriteCond %{QUERY_STRING} !X-Plex
RewriteCond %{HTTP:X-Plex-Product} !\w+
|
Step 3 (http with no security and port restrictions -> valid for non-Zyxel users too):
This configuration won't work if the Plex's port specified with "Server is mapped to port" (by default is 32400) is not accessible!
Replace (if you have it) AuthZyxelSkipPattern with AuthZyxelSkipPattern /plex, .
Include the code below outside of any </VirtualHost> directive.
# BEGIN plex
RewriteRule ^/plex/?$ /plex/web/index.html [R=301]
<location /plex/>
ProxyPass http://127.0.0.1:32400/
ProxyPassReverse http://127.0.0.1:32400/
ProxyPassReverseCookiePath / /plex/
ProxyPassReverseCookieDomain 127.0.0.1 adrhc.asuscomm.com
</location>
# END plex
Put the code above between <VirtualHost *:443> and </VirtualHost> in order to access plex over https too but with same restrictions related to ports.
Step 3 (http with no security and NO port restrictions -> valid for non-Zyxel users too):
Replace (if you have it) AuthZyxelSkipPattern with AuthZyxelSkipPattern /plex, .
Include the code below outside of any </VirtualHost> directive.
# BEGIN plex
RewriteRule ^/plex/?$ /web/index.html [R=301]
ProxyPass /web/ http://127.0.0.1:32400/web/
ProxyPassReverse /web/ http://127.0.0.1:32400/web/
ProxyPassReverseCookieDomain 127.0.0.1 replace_this_with_your_wan-ip_or_domain-name
ProxyPass /photo/:/ http://127.0.0.1:32400/photo/:/
ProxyPassReverse /photo/:/ http://127.0.0.1:32400/photo/:/
ProxyPassReverseCookieDomain 127.0.0.1 replace_this_with_your_wan-ip_or_domain-name
ProxyPass /:/websockets/ http://127.0.0.1:32400/:/websockets/
ProxyPassReverse /:/websockets/ http://127.0.0.1:32400/:/websockets/
ProxyPassReverseCookieDomain 127.0.0.1 replace_this_with_your_wan-ip_or_domain-name
ProxyPassMatch ^/(\w+-\w+-\w+-\w+-\w+)$ http://127.0.0.1:32400/$1
ProxyPassReverseCookieDomain 127.0.0.1 replace_this_with_your_wan-ip_or_domain-name
RewriteCond %{REQUEST_URI} !^/plexx
RewriteCond %{HTTP:X-Plex-Product} \w+
RewriteRule .* http://%{HTTP_HOST}/plexx%{REQUEST_URI}?%{QUERY_STRING} [NE,B]
RewriteCond %{REQUEST_URI} !^/plexx
RewriteCond %{QUERY_STRING} X-Plex
RewriteCond %{REQUEST_URI} !^/photo/:/
RewriteRule .* http://%{HTTP_HOST}/plexx%{REQUEST_URI}?%{QUERY_STRING} [NE,B]
ProxyPass /plexx/ http://127.0.0.1:32400/
ProxyPassReverse / http://127.0.0.1:32400/
ProxyPassReverseCookiePath / /
ProxyPassReverseCookieDomain 127.0.0.1 replace_this_with_your_wan-ip_or_domain-name
# END plex
Step 3 (with https and requiring Zyxel console authentication):
Replace AuthZyxelSkipPattern with AuthZyxelSkipPattern /plex, .
Include the code below EXACTLY before </VirtualHost> which is enclosing <VirtualHost *:443> directive.
# BEGIN plex
RewriteRule ^/plex/?$ /web/index.html [R=301]
ProxyPass /web/ http://127.0.0.1:32400/web/
ProxyPassReverse /web/ http://127.0.0.1:32400/web/
ProxyPassReverseCookieDomain 127.0.0.1 replace_this_with_your_wan-ip_or_domain-name
ProxyPass /photo/:/ http://127.0.0.1:32400/photo/:/
ProxyPassReverse /photo/:/ http://127.0.0.1:32400/photo/:/
ProxyPassReverseCookieDomain 127.0.0.1 replace_this_with_your_wan-ip_or_domain-name
ProxyPass /:/websockets/ http://127.0.0.1:32400/:/websockets/
ProxyPassReverse /:/websockets/ http://127.0.0.1:32400/:/websockets/
ProxyPassReverseCookieDomain 127.0.0.1 replace_this_with_your_wan-ip_or_domain-name
ProxyPassMatch ^/(\w+-\w+-\w+-\w+-\w+)$ http://127.0.0.1:32400/$1
ProxyPassReverseCookieDomain 127.0.0.1 replace_this_with_your_wan-ip_or_domain-name
RewriteCond %{REQUEST_URI} !^/plexx
RewriteCond %{HTTP:X-Plex-Product} \w+
RewriteRule .* https://%{HTTP_HOST}/plexx%{REQUEST_URI}?%{QUERY_STRING} [NE,B]
RewriteCond %{REQUEST_URI} !^/plexx
RewriteCond %{QUERY_STRING} X-Plex
RewriteCond %{REQUEST_URI} !^/photo/:/
RewriteRule .* https://%{HTTP_HOST}/plexx%{REQUEST_URI}?%{QUERY_STRING} [NE,B]
ProxyPass /plexx/ http://127.0.0.1:32400/
ProxyPassReverse / http://127.0.0.1:32400/
ProxyPassReverseCookiePath / /
ProxyPassReverseCookieDomain 127.0.0.1 replace_this_with_your_wan-ip_or_domain-name
# END plex
Step 4 (valid for both http with no security and port restrictions and http with no security and NO port restrictions):
Access this url in order to open Plex page:
https://replace_this_with_your_wan-ip_or_domain-name/plex
Step 4 (with https and requiring Zyxel console authentication):
First: login using the Zyxel administration console; the url it's something like the one below (the exact one depends on your installed firmware version):
https://replace_this_with_your_wan-ip_or_domain-name/r39679,/adv,/loginwrap.html
Second: in order to access Plex page open a new browser tab with the following url:
https://replace_this_with_your_wan-ip_or_domain-name/plex
* It's important to use only https; won't work over http.