Tag Archives: apache

How to make Plex media server available from remote without having an account through apache

Hello there. 

Plex Media Server

I use Plex (plex.tv). It’s a fantastic tool to manage your videos and movies. You stream anything to anything with a modern browser.  The thing is, if you want to be able to share your stuff through the Internet and see a film you’ve got at a friends house, you need to create an online account on the Plex home page. I’m not to fond of creating accounts sharing what I have. 

There are several ways you can reach your plex meda server from the outside, but in this post we’re gonna use apache (you need to install it if you don’t already have it installed).  In my home network I have my own web server (if you are reading this you’re on it right now ;).  Also on the same network I have got my own proper Ubuntu server with Plex installed.

How do we connect the two services? Apache has got this neat thing called ProxyPass and ProxyPassReversed. So what I did was the following:

  • Create a subdomain
  • Create a .conf file for apache (see below):
  • sudo vim /etc/apache2/sites-available/subdomain.jima.cat.conf
  • Then “cd /etc/apache2/sites-enabled” and make a link:
  • sudo ln -s ../sites-available/subdomain.jima.cat.conf subdomain.jima.cat.conf
  • Restart apache: sudo service apache2 restart

This is the .conf file. You need to change all marked in bold to your own values. The part in blue is only needed if you would like some sort of protection. This makes it impossible for anyone to enter your site without a proper username and password. You can see how to create the password file here.

<VirtualHost *:80>
   ServerName "subdomain.domainname.com:80"
   ServerAdmin "admin@domainname.com"
   ProxyPass / http://192.168.2.51:32400/
   ProxyPassReverse / http://192.168.2.51:32400/

   CustomLog /var/www/vhosts/domainname.com/logs/subdomain.access_log common
   ErrorLog "/var/www/vhosts/domainname.com/logs/subdomain.error_log"

   ProxyPreserveHost on
   <Proxy *>
      AuthType Basic
      AuthName "password protected..."
      AuthUserFile "/var/www/vhosts/domainname.com/.htpasswd"
      Require valid-user
   </Proxy>

</VirtualHost>

Now try from the outside: http://subdomain.domainname.com/web

Cheers
/jima

Password Protect a Directory Using .htaccess

Hello there. Today we’re gonna look on how to password protect a specific folder with help of apache and it’s fantastic .htaccess file.

Lock Folder

This is done in a moment. Start by entering the folder you want to protect. Open the .htaccess file with your favorite editor and type in the following:

AuthType Basic
AuthName "restricted area"
AuthUserFile /var/www/vhosts/my-domian.com/httpdocs/folder/.htpasswd
require valid-user

AuthName is a text that will appear when trying to enter the folder and you can type just anything.
AuthUserFile The path to your .htpasswd file. It’s recommended to put this file in the same folder you want to protect. The .htaccess and .htpasswd files should be protected by the apache server by default so no user can download those two files.

If you don’t know your complete AuthUserFile path you could create a php file with “phpinfo();” in it. This will show you the correct path to your html folder.

Ok. Now we need to create the .htpasswd file. The first time you need to add the “-c” option

htpasswd -c .htpasswd username

You will now be asked to type in a password. Your are done. Now try to enter the folder. 
To add more user you do the same command without the -c option (it means create and will give you an error if the file already exist)

htpasswd .htpasswd username2

 

Cheers
/jima