@DerKeyser said:
Hmmm, I don’t seem to quite get what your proxy actually does with the
if ($arg_X-Plex-Token = '') {
rewrite ^/$ https://$http_host/web/index.html;
}
statement in it’s config. I’m a bit of a noob when it comes to http proxy’ing.
I know that without that conditional rewrite my plex server becomes “Unavailable”.
From my understanding, when you open a browser and navigate to https://plex.mydomain.com your browser issues a GET request for the path / to the appropriate server. In this request the X-Plex-Token argument does not exist, so you would get redirected to /web/index.html which your browser would then issue another request for, again without the X-Plex-Token argument. This time you won’t get redirected even though the X-Plex-Token argument does not exist becuase the rewrite explicitly matched ^/$. In regex ^ means beginning of line, and $ means end of line. Since this new request contains /web/index.html and not just / the rewrite does not execute. Within the index.html there are a lot of <script> tags that reference javascript files. Your browser goes and gets them as well, still without X-Plex-Token. Once the javascript is loaded from your server the writers of Plex can make the URL requests look like whatever they want. So when the login page appears and you login with your credentials, you get back a valid Plex login token from plex.tv which the javascript then inserts into all of the URL requests as an argument/parameter so that your Plex server knows you already logged in and doesn’t present you with the login screen again (I think).
The first request that my browser makes to my plex server after logging in is
https://plex.mydomain.com/?X-Plex-Product=Plex Web&X-Plex-Version=2.12.5&X-Plex-Client-Identifier=<client id>&X-Plex-Platform=Firefox&X-Plex-Platform-Version=50.0&X-Plex-Device=Windows&X-Plex-Device-Name=Plex Web (Firefox)&X-Plex-Device-Screen-Resolution=1293x210,1920x1080&X-Plex-Token=<token>.
This request does not fall under /web, but the plex server does respond with an XML file.
If the above request was made and the condition in the Nginx config was not present, it would get redirected to /web/index.html which would not return the expected XML file. This appears to be the only request, that is made from loading the homepage, that would match the rewrite rule (as explained above) but evidently it is enough to make the plex server you are connecting to “Unavailable”.
Are clients referencing a URL outside of the https://yourdomain/web URL (Not in /web) that you need to catch and rewrite to access the standard URL?
Other paths outside of /web that I can see Plex access just from loading the homepage of my plex server are:
/
/status
/clients
/updater
/library
/activities
/hubs
/photo
It appears that the only problematic path is /.
You are looking for an empty X-Plex-Token argument and then you rewrite the URL to access the default index page. I fail to see why that makes it work unless it’s because your proxy removes that argument by default.
My proxy does not remove the argument, it is never sent by the browser on the initial request for plex.mydomain.com.
Sorry if this response is a little long, or you already knew some of what I mentioned, I was trying to document what I was seeing/thought so that in a month when I forget how I came up with the Nginx config I have I can look back here. And hopefully this will help someone else that runs across this thread.