Plex on a VPS (Ubuntu 16.04) with LetsEncrypt SSL

in plex •  6 years ago  (edited)

BlogPost2.png

Installing Plex on Ubuntu 16.04

Steps to install Plex server on your VPS. This tutorial is tested on Ubuntu 16.04

SSH to your server

ssh [email protected]

Enable Plex Server repository on Ubuntu. Source

echo deb https://downloads.plex.tv/repo/deb public main | sudo tee /etc/apt/sources.list.d/plexmediaserver.list

curl https://downloads.plex.tv/plex-keys/PlexSign.key | sudo apt-key add -

Download .deb file from Plex. Source

wget https://downloads.plex.tv/plex-media-server/1.13.9.5456-ecd600442/plexmediaserver_1.13.9.5456-ecd600442_amd64.deb

sudo dpkg -i plexmediaserver_1.13.9.5456-ecd600442_amd64.deb.deb

Open in your web browser:

http://127.0.0.1:32400/web 
or
http://your-domain.tld:32400/web

(Optional) Socks5 Proxy:

ssh -D 8123 -f -C -q -N user@vps-ip

and then open on your computer (not on vps).

http://127.0.0.1:32400

Installing LetsEncrypt Certificate (with Nginx)

To install LetsEncrypt certificate, it requires Certbot. Source

$ sudo apt update
$ sudo apt install software-properties-common
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt update
$ sudo apt install python-certbot-nginx 

and now configure Certbot:

sudo certbot --nginx

On successful configuration, it will show you the path of Certificate and Key. (Please note them for using in next steps)


Configuring nginx

Permanent redirect from HTTP to HTTPS, open

nano /etc/nginx/sites-enabled/your-web.conf

and then make sure you add 301 redirect.

server {
  listen 80;
  listen [::]:80;

  server_name plex.your-domain.tld;

  return 301 https://$server_name$request_uri;
}

Now, open your ssl-config of nginx e.g.,

nano /etc/nginx/sites-enabled/your-web-ssl.conf

Edit the file as:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name plex.your-domain.tld;
    
    ssl_certificate /etc/letsencrypt/live/plex.your-domain.tld/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/plex.your-domain.tld/privkey.pem;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
    include /etc/nginx/snippets/ssl-params.conf;
    
    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:32400;
    }
}    

Save the file, and restart nginx:

sudo systemctl restart nginx

Now browse your plex server at:

https://plex.your-domain.tld
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!