A Reverse proxy is a cool way to remotely access your media server's web interfaces. When you are done with this guide you will be able to use your free dynamic DNS address (Mac Afraid DNS Guide) like htpcguides.crabdance.com/couchpotato instead of htpcguides.crabdance.com:5050. This means fewer open ports on your router leaving you more secure while simultaneously having a convenient URL to access CouchPotato behind an nginx reverse proxy. This guide was tested on Mac OSX Mavericks but should work on any version like Mountain Lion or Yosemite.
Configure CouchPotato Reverse Proxy Mac OSX
Setup CouchPotato for a Reverse Proxy
To prepare CouchPotato for use in a reverse proxy, open up the webui at http://ip.address:5050
In the interface, go to Settings, click General, check off Show Advanced Settings
Scroll down to Url base and add /couchpotato.
You should add a username and password too for security
Restarting CouchPotato is a good idea
Open Terminal and Install X-Code
Open up terminal which you can find Terminal in Applications -> Utilities
Now Scroll down to Terminal and open it
The Mac Terminal is nice and white.
Nginx requires command line tools on the Mac in order to compile nginx from source.
Install x-code tools with this command.
xcode-select --install
You will get a pop up asking to install command line tools. Click Install.
If it says it couldn't be found then you already have command line tools installed
Build nginx from Source for Mac OSX
Instructions adapted from Kevin Worthington's site
In the terminal (which is not that scary) all you have to do is copy and paste these commands.
We need to build PCRE which is a perl module first for nginx to use during building
Enter the Applications folder
cd /Applications
Create a directory for building
mkdir nginx
Enter directory for building
cd nginx
Download the latest Perl PCRE module
wget http://sourceforge.net/projects/pcre/files/pcre/8.36/pcre-8.36.tar.gz
Extract the PCRE module
tar -xvf pcre-8.36.tar.gz
Enter the PCRE module
cd pcre-8.36
Configure the pcre module
./configure
Go up one directory level to /Applications/nginx
cd ..
Download nginx
wget http://nginx.org/download/nginx-1.6.2.tar.gz
Unpack nginx
tar -xvf nginx-1.6.2.tar.gz
Enter nginx folder
cd nginx-1.6.2
Configure nginx for compiling with pcre
sudo ./configure --prefix=/usr/local/nginx --with-cc-opt="-Wno-deprecated-declarations" --with-http_ssl_module --with-pcre=/Applications/nginx/pcre-8.36
sudo make
sudo make install
Start nginx
sudo /usr/local/nginx/sbin/nginx
Open up a browser and navigate to http://ip.address and you should see the default nginx page which looks like this
Time to create the CouchPotato reverse proxy on Mac OSX
Open the nginx configuration file
sudo nano /usr/local/nginx/conf/nginx.conf
Find this section and change your server_name localhost to your dynamic dns address and your media server's local IP address
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
Mine looks like this so I can access it locally and remotely. htpcguides.crabdance.com needs to be replaced with your own dynamic DNS address and 192.168.40.100 needs to be replaced with your home media server's local IP address.
server {
listen 80;
server_name htpcguides.crabdance.com 192.168.40.100;
#charset koi8-r;
#access_log logs/host.access.log main;
Underneath the #access_log
line, add these lines. 127.0.0.1 points to the loopback address on your media server
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;
}
The whole section will now look like this
server {
listen 80;
server_name htpcguides.crabdance.com 192.168.40.100;
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;
}
Autostart nginx on boot using this plist upstart script thanks to Hunter
sudo nano /Library/LaunchDaemons/nginx.plist
Paste the working nginx plist code
<plist version="1.0">
<dict>
<key>Label</key>
<string>nginx</string>
<key>Program</key>
<string>/usr/local/nginx/sbin/nginx</string>
<key>KeepAlive</key>
<true/>
<key>NetworkState</key>
<true/>
<key>LaunchOnlyOnce</key>
<true/>
</dict>
</plist>
You can also try http://ip.address/couchpotato and you should see the CouchPotato interface
You may delete the /Applications/nginx folder
In terminal this command will do it or you can use the GUI.
sudo rm -R /Applications/nginx
If you are running a Mac OSX version other than Mavericks, please let me know in the comments if this guide worked for you on another version.
Don't forget to forward port 80 on your router if you want to access the reverse proxy using dynamic DNS