You finished Part 1 - Enabling CloudFlare. Now we'll set it up to work with Plex.
Before we go any further though, it is important to check if your website works properly with CloudFlare. So go and visit your Plex subdomain. In my case, plex.techperplexed.ga. What you should see after a minute or so:
Perfect! That means your site is properly managed by CloudFlare. If you don't see a similar image as the above on your own site, don't proceed, but go back to part 1 and check all your steps thoroughly.
When your site is configured with CloudFlare, you can now set up Plex to do the same. Go to https://app.plex.tv/ to visit your Plex server and go to the Settings.
Click Network, make sure "Preferred" is selected next to Secure connections, then click "Show Advanced".
Scroll down to "Custom server access URLs" and type the following:
This is what mine looks like:
Click "Save Changes".
Next, go to Remote Access and click "Disable Remote Access"
Whaaat? But we went through such trouble to enable it in Part 3 of the Plex tutorial! Yeah, I know... trust me, it's necessary. It will now display in red that your server is not available outside your network.
Next, we need to configure your VPS.
Creating the CloudFlare script
Start a PuTTY session with your own username.
Before you proceed, make sure you followed the steps described in "Getting the firewall ready for Plex" in Part 2 - Configuring Ubuntu. Setting up CloudFlare properly is dependent on an active UFW firewall.
Check if socat is installed (it should be already):
sudo apt-get install socat
Create the CloudFlare script:
sudo nano /etc/systemd/system/plexproxy.service
Paste the following:
Description=Proxy 8443 to 32400 internally but not externally
After=syslog.target local-fs.target network.target
ExecStart=/usr/bin/socat tcp-listen:8443,reuseaddr,fork tcp:localhost:32400
Save with Ctrl-O, Enter, then Ctrl-X. Enable the script:
sudo systemctl enable plexproxy.service
Start the service:
sudo service plexproxy start
Then reload the services.
Remember how we set up a firewall in Part 2 of the Plex tutorial? We opened port 32400 for use of Plex. Because CloudFlare is taking over, we now need to close the port. Type
sudo ufw delete allow 32400
(If you get an error, try "sudo ufw delete allow 32400/tcp" instead)
Now add port 8443 by typing
sudo ufw allow 8443
You can check if your port changes went correctly by typing:
sudo ufw status
It should look somewhat like this:
Check your Plex server
That is all there is to it. If all went well, you can now visit https://plex.yourdomain:8443 in your browser. You probably have to login, but everything should work properly.
Congratulations! Please let me know in the comments if you experience a faster Plex through CloudFlare!