Configure HTPC Manager Reverse Proxy nginx Windows

nginx-htpc-managerA Reverse proxy is a convenient method 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 (Windows Afraid DNS Guide) like htpcguides.crabdance.com/htpc instead of htpcguides.crabdance.com:8085. This means fewer open ports on your router leaving you more secure while simultaneously having a convenient URL to access HTPC Manager behind an nginx reverse proxy. This guide was tested on Windows 8 but should work on Windows 7 and Windows Server editions too. Make sure you have installed HTPC Manager on Windows first.

Configure HTPC Manager Reverse Proxy Windows

Configure HTPC Manager for Reverse Proxy

Go to your HTPC Manager web interface at http://ip.address:8085

Click the settings drop down in the top right and choose Settings

Click General and adjust Webdir to the easy to remember location where you want to access HTPC Manager

For Webdir I have left the existing / and added htpc after it.

You should also choose a username and strong password if you want access outside your home network.

htpc manager reverse proxy 1

Scroll down, leave the reverse proxy header sections empty, nginx handles this part

Click Save and restart HTPC Manager

You do not need to enable SSL here, nginx will handle SSL (creating certificate guide here) and there is no reason to SSL behind SSL.

htpc manager reverse proxy 2

Configure nginx with HTPC Manager Reverse Proxy

Grab the latest stable nginx, or you can also just use the current version you may already have installed. The current latest stable version is 1.8.0 which you can download from this page.

Unpack it to c:\nginx-1.8.0 by dragging the folder to the C: drive

Open the configuration file in c:\nginx-1.8.0\conf\nginx.conf with Notepad or Notepad++

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, replace the red text with your dynamic DNS address and the server's local IP

server {
        listen       80;
        server_name  htpcguides.crabdance.com 192.168.40.105;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

Underneath add these lines, the location must match what you set the Webdir to in HTPC Manager

location /htpc {
		proxy_pass http://127.0.0.1:8085;
		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 nginx server section will now look something like this

server {
        listen       80;
        server_name  htpcguides.crabdance.com 192.168.40.105;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

Run a command prompt as an Administrator and enter these commands to start nginx, it may need to be nginx-1.6.2

c:
cd c:\nginx-1.8.0
start nginx

See if you can access HTPC Manager at your server's IP address http://ip.address/htpc

Let's make nginx start on boot, you can use a Windows system service or run a .vbs script. The Windows system service method will work on all versions of Windows including Windows Server editions.

nginx Windows System Service

Download NSSM from here, the latest stable release is a good idea – it includes 32-bit and 64-bit

Open the nssm.zip and go into either the Win32 (32-bit) or Win64 (64-bit) folder depending on your Windows version.

Copy the nssm.exe to your C:\Windows\System32 folder so it is part of your PATH which allows you to run commands from any directory in the command prompt without having to be in the executable's actual path. You will get a warning about needing permission, grant it.

windows system service copy nssm

Run a Windows command prompt as an Administrator

Create the nginx service with this command

nssm install nginx

You will see the NSSM screen, click to choose the nginx.exe Path and browse to your nginx installation

Click Install service

nssm nginx windows system service

Now you will need to reboot the machine and nginx will automatically start

You can start and restart nginx with these commands in a command prompt running as Administrator

net stop nginx
net start nginx

nginx Windows VBS Script

Create nginx.vbs in c:\nginx-1.8.0

Dim sh
Set sh = WScript.CreateObject("WScript.Shell")
sh.run "cmd /K CD C:\nginx-1.8.0\ & start nginx", 0

Create a shortcut and drag it to your startup folder

Reboot and nginx should start automatically

If you ever edit your nginx.conf file you can reload the configuration with this command in the Windows command prompt

c:\nginx-1.8.0\nginx -s reload

If you want to access the reverse proxy outside your home network using your dynamic DNS address forward port 80 on your router