[PHP] PlexAuth - Authentication for your domain using Plex

okay, to clear up some things, the version of NGINX i have installed is 1.9.3, your instruction say’s that’s fine; but the next step refers to 1.9.5 and having to add a source list. do i need to remove nginx and install 1.9.5?

Step three is only if you are running nginx version lower than 1.5.4. I’ll add a message to make that a bit more clear.

On step 15 through 18 where you do have a tag to say edit as needed, i removed plexauth from both names so it was set as ./inc/ since i was already in plexauth folder. Step 19 and 20, i had cd … back down 1 directory then, so i can apply the chown, chmod commands.

Additionally, add in the final steps, 21 and ongoing to configure config.ini.php and footer.php.

Used plexpy token, plex account owner username, and changed urls in the footer.

also edited www.conf with my domain url where specified.

then tested plexauth @ 192.168.11.37/plexauth which i get my normal result; 502 bad gateway.

Edit: also after everything was done, and i got the 502 error, i ran the command # sudo service nginx restart and gave it a few minutes to do its thing. Tested 192.168.11.37/plexauth and i got the sign in page. Signed in with my plex credentials / email. and it is working. SWEET!!

Now… what do i need to do, to have everything use this authentication? what kind of php script do i need or where to place things so they need to use this login? looks like i just need to edit the footer.php page with urls? and the side menu?
this uses a cookie, so no log out option.

aditionally, looks like this broke everything else nginx had setup; due to www.conf? i will need to edit that with your changes in it then. i have a backup of my original www.conf file i can try and get plexauth added to it.

When I say “Edit as needed” I was referring to editing the actual file which is why I haven’t included that down lower.

502 bad gateway at that point sounds like a permissions issue with PHP. You can confirm this by checking your log for something like this:

connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied)

Here are some instructions on how to fix that.
https://it.awroblew.biz/php5-fpm-sock-failed-13-permission-denied-while-connecting-to-upstream-error/

Oh, i see. edit the file. not the command line for where it goes. I understand. i will edit the nav.php too then.

still working on editing www.conf for now as well.

@m1e1w1 said:
Edit: also after everything was done, and i got the 502 error, i ran the command # sudo service nginx restart and gave it a few minutes to do its thing. Tested 192.168.11.37/plexauth and i got the sign in page. Signed in with my plex credentials / email. and it is working. SWEET!!

Fantastic!

Now… what do i need to do, to have everything use this authentication? what kind of php script do i need or where to place things so they need to use this login? looks like i just need to edit the footer.php page with urls? and the side menu?

Those URL’s are only links. They have nothing to do with PlexAuth itself. If you wish to secure something with PlexAuth add a location block in your nginx config.

example of reverse proxy:

location /sickrage {
        auth_request /admin_auth/; #This requires the user to be in a sickrage allowed list.
        proxy_pass http://127.0.0.1:8081;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

example of website:

location /content {
	auth_request /auth/;
	root /var/www/html/index.html;
}

this uses a cookie, so no log out option.

No, I haven’t added a logout option. Only way to do this at the moment is to delete both the PHP session cookie and the RememberMe cookie.

aditionally, looks like this broke everything else nginx had setup; due to www.conf?

You don’t need to keep the www.conf name, this can be anything.

okay, i’m at a point where i can ether get plexauth to load its directory which is working; or the rest of nginx web pages but not both.

i determined that /etc/nginx/conf.d/www.conf file and /etc/nginx/sites-available/default file are conflicting.

i tried merging the 2 files code together, as www.conf and default as well, but no luck.

my existing sites, such as HTPC and Sonarr, Sabnzbd work under the /sites-available/default file, while plexauth only works under the /conf.d/www.conf file. what might i need to do, so that both work, and i can use the auth and admin_auth?

I refereed to your example blocks, and i have them in place exactly as your example shows, but pages wont load for me. If i use just www.conf, then just plexauth page works. if i use /sites-available/default, then everything else works, just not plexauth.

I might have repeated myself, sorry about that.

@m1e1w1 said:
okay, i’m at a point where i can ether get plexauth to load its directory which is working; or the rest of nginx web pages but not both.

i determined that /etc/nginx/conf.d/www.conf file and /etc/nginx/sites-available/default file are conflicting.

i tried merging the 2 files code together, as www.conf and default as well, but no luck.

my existing sites, such as HTPC and Sonarr, Sabnzbd work under the /sites-available/default file, while plexauth only works under the /conf.d/www.conf file. what might i need to do, so that both work, and i can use the auth and admin_auth?

I refereed to your example blocks, and i have them in place exactly as your example shows, but pages wont load for me. If i use just www.conf, then just plexauth page works. if i use /sites-available/default, then everything else works, just not plexauth.

I might have repeated myself, sorry about that.

Check your nginx.conf. /etc/nginx/nginx.conf depending on what it says in there is where your config files need to go.

Generally your nginx.conf will have a line “include /etc/nginx/sites-enabled/*;” So all files in this folder are read.

Could you post your deafult config file? The issues here are definitely not with PlexAuth

I do have both lines in nginx.conf,
include /etc/nginx/conf.d/.conf;
include /etc/nginx/sites-enabled/
;

I have no files in /sites-enabled/ but i have a file in /sites-available/

PM’d the default file to you.

I have this working with the openflixr beta3, with a few updates that @hjone72 changed to the github release.

The existing configurations with what is included with openflixr have no problems with replacing the default authentication method with plexauth.

@m1e1w1 Could you share a sanitized version of your final nginx.conf?

There are also two examples here;

@DallasHQ Sure, but so you know, i am not using the recommended www.conf as @hjone72 has in his guide. My install only uses a modified sites available file from openflixr beta 3. The file called reverse.

I have attached it here, with the steps i used to install PlexAuth in openflixr beta 3. The zip should contain 2 files, reverse_fixed_clear and install_plexauth_openflixr_beta3.txt

Rename the reverse_fixed_clear file to reverse.

I keep having this issue…" A session had already been started - ignoring session_start() in /usr/share/nginx/html/plexauth/auth/index.php on line 35" while reading response header from upstream"…leading to a 401 unauthorized message with a login screen never appearing…

@DallasHQ said:
I keep having this issue…" A session had already been started - ignoring session_start() in /usr/share/nginx/html/plexauth/auth/index.php on line 35" while reading response header from upstream"…leading to a 401 unauthorized message with a login screen never appearing…

I’ve actually fixed that in a commit I haven’t pushed to github yet. Its not important and its not the reason you are getting 401

EDIT: The change has been pushed to GitHub.

Thanks I’ll continue to work through the issue, I have your recommended setup in nginx and all the necessary permission for folders (even the session folder). Even if I clean the sessions folder, any request to “http://localhost:8087/auth/” throws me the “A session had already been started - ignoring session_start”.

It isn’t a very important error and is definitely not causing any 401 errors. I missed a session_start();

Pushing a commit now that should fix it. :slight_smile:

Still digging, using your default setup in example 1 for nginx. This is what I’ve discovered in regards to the sessions issue (I’m only having trouble with this one app in regards to PHP).

I can load up plexauth/index.php (which requires once “include.php”) and successfully log in with my credentials. No errors thrown and a session file is created in “session_path” successfully".

If I try to go up a folder level on a NEW SESSION (all others cleared in session_path) to plexauth/auth/index.php, which is what is pushed to the server listening on 8087 (/auth/) it fails immediately, plus a blank session file is created in “session_path”. Furthermore, this is the message I’m greeted with.

I never see via plexauth/auth/index.php:

I’ve ran through my setup for permissions, cache mgmt, php.ini (session.auto_start is not enabled), www.conf (tried php5-fpm.sock and 127.0.0.1:9000), and also checked to see if another plugin initialized a session (which returned nothing). I haven’t had success either inserting a piece of “session_destroy” in the code, found mention of it for this issue.

Lastly, I’ve been trying to convert over from auth_basic (which functions but plexauth is the best way to handle authentication for what I’m trying to do). I’m getting close to the finish line. Thanks.

@DallasHQ said:
If I try to go up a folder level on a NEW SESSION (all others cleared in session_path) to plexauth/auth/index.php, which is what is pushed to the server listening on 8087 (/auth/) it fails immediately, plus a blank session file is created in “session_path”. Furthermore, this is the message I’m greeted with.

Sorry I missed another session_start() just delete line 37 in that file and that error should go away. It isn’t even needed. I’ve also now pushed a commit with the line deleted.

Hit me up via PM and we can work this out :slight_smile:

Big shout out to the developer of this great solution, was stuck on a weird 401 issue for days (was able to login via other methods) via auth_requests module. Developer helped me out from the beginning to to the end, he went out of his way so I appreciate that. I was able to successfully link Nginx + plexauth to utilize php iFrame solutions such as Muximux. If you are running everything off one domain with web paths (no subdomains) then I recommend you check out the dev’s latest nginx example found on his github or this pastebin: http://pastebin.com/JCuG8TPN. Please note he does have Nginx examples for a subdomain setup. Lastly, you don’t have to utilize his launch page either (which is good), you can replace the launch page with Muximux/ManageThis etc… The developer will have more tips on how to do this on his Github.