Configure CouchPotato Reverse Proxy nginx Linux

nginx-couchpotato-reverse-proxyConfigure CouchPotato Reverse Proxy nginx Linux to conveniently access your media list on your home media server or NAS. When you are away from home then you can log in to your server and see the CouchPotato web interface. For ultimate convenience with your reverse proxy for people with dynamic IP addresses, use a free dynamic DNS service like AfraidDNS (guide for automating), DuckDNS or No-IP.

After implementing a CouchPotato reverse proxy you can access CouchPotato via your custom DNS address like http://htpcguides.crabdance.com/couchpotato instead of http://IP:5050. This CouchPotato reverse proxy how-to was tested on Debian and Ubuntu but the nginx virtual host should work on any Linux system (CentOS, Red Hat, Fedora, Arch etc).

Configure CouchPotato for Reverse Proxy nginx Linux

CouchPotato supports custom URL bases so we need to set that first.

After the custom URL base (e.g. /couchpotato) is set we can use nginx to proxy that location from the internet IP or Dynamic DNS address to CouchPotato.

Configure CouchPotato for Reverse Proxy

Open up your CouchPotato web interface on http://ip.address:5050/settings

Click General, then under Basics set a username and password

Note: you may want to use basic HTTP auth so you can get some brute force protection (guide).

couchpotato-nginx-reverse-proxy-basics-min

Then toggle Show advanced in the top right corner.

Scroll down to Advanced and set your Url Base to /couchpotato

This Url Base will be the location you use in the nginx virtual host.

Note: The Proxy Username and Password are autofilled with the information you set under Basic in the previous step after you restart CouchPotato

couchpotato-nginx-reverse-proxy-advanced-min

Choose settings in the bottom left and choose Restart.

couchpotato-nginx-reverse-proxy-restart-min

Now when you access CouchPotato's web interface by its port and Url Base e.g. http://ip.address:5050/couchpotato

Configure nginx as Reverse Proxy for CouchPotato

Install nginx

sudo apt-get install nginx -y

Create a new nginx site

sudo nano /etc/nginx/sites-available/reverse

Add these lines, adjust your dynamic dns address and local IP address. If you changed your default CouchPotato port change 127.0.0.1:5050 to reflect your port. If you used a Url Base that was not /couchpotato then replace /couchpotato with your custom location.

For the reverse proxy to work, the Url Base in CouchPotato must match the nginx location or you will get 502 Bad Gateway.

If you already have an nginx reverse proxy set up you only need to add the blue block location.

server {
listen 80;
server_name htpcguides.crabdance.com, 192.168.40.105;
error_log /var/log/nginx/reverseproxy.log;

location /couchpotato {
    proxy_pass http://127.0.0.1:5050;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

Ctrl+X, Y and enter to save and exit

Disable the default nginx site

sudo unlink /etc/nginx/sites-enabled/default

Enable the reverse proxy site with CouchPotato enabled

sudo ln -s /etc/nginx/sites-available/reverse /etc/nginx/sites-enabled/reverse

Test the nginx configuration is valid and working

sudo nginx -t

Restart the nginx service

sudo service nginx restart

Start the CouchPotato service

sudo service couchpotato start

You can now access CouchPotato locally within your home network at http://ip.address/couchpotato or using your dynamic DNS address.

For maximum security consider using https for your reverse proxy to encrypt communication over the internet.