Skip to content

Instantly share code, notes, and snippets.

@erodewald
Last active October 2, 2023 04:28
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save erodewald/cfed87b4ec3f362006bb to your computer and use it in GitHub Desktop.
Save erodewald/cfed87b4ec3f362006bb to your computer and use it in GitHub Desktop.
Reverse proxy on Windows with Apache 2.4 for Couchpotato/Sonarr

###Pre-requisites:

  1. Any version of Windows newer than XP or Server 2003.
  2. A good text editor. I recommend Sublime Text 2.
  3. If you use Sublime Text, you can get very helpful syntax highlighting while editing Apache Conf files by installing Package Control. Once fully installed and SublimeText is restarted, CTRL+SHIFT+P -> Install Package -> ApachConf (enter).
  4. This assumes you have a public domain pointing to your WAN IP. Figure that out from whatismyip.com. If you purchase a domain and use a CNAME or A-record, it can take some time for the DNS changes to propagate. I've seen anywhere from 15 mins to several hours.
  5. Within your router, you must forward port 80 to your LAN IP which hosts Apache.

###Install Apache 2.4 on Windows

  1. Download Apache for Windows. Since Apache only distributes source code, implementations can differ based on who you get it from. I chose Apache Lounge because some other versions include php, mySQL, and they just aren't necessary for such a simple task.
  2. Install VC11 Redistributables x86/x64.
  3. Download the Apache binary appropriate for your OS: x86 or x64.
  4. Extract to your root OS directory, i.e. C:\, so the directory structure looks like C:\Apache24\bin

###Configure Apache 2.4 to listen on your desired port

  1. NOTE: At any time, you can check your conf syntax by opening an elevated command prompt, CDing to C:\Apach24\bin, then executing httpd -t.
  2. In your command prompt, within Apache24\bin, execute httpd -k install to install the Apache service.
  3. NOTE: You will have to stop and start this service often. From the cmd prompt: net start apache2.4, or net stop apache2.4.
  4. Alternatively, just paste this into the elevated command prompt. net stop apache2.4 && net start apache2.4
  5. Save this file as restart_apache.bat on your desktop or something. Right click, properties.
  6. Open Apache24\conf\httpd.conf in your favorite text editor.
  7. If you want to choose something other than port 80 for HTTP traffic, set your listen port. CTRL+F for Listen
  8. CTRL+F for ServerName. Uncomment the line by deleting the '#', and set the value to either your chosen domain or IP address.
  9. Start the service and point your browser to localhost. It should report back "It works!".
  10. CTRL+F for mod_proxy. Uncomment the lines: proxy_module, proxy_http_module.
  11. CTRL+F for mod_vhost. Uncomment this line.
  12. CTRL+F for Include conf/extra/httpd-vhosts.conf. Uncomment this line.
  13. Save the file.

###Configure virtual hosts

  1. Open Apache24\conf\extra\httpd-vhosts.conf in a text editor. This is where we'll define your reverse proxy configurations.

  2. If this virtual host differs from the main configuration found in httpd.conf, you can define them per virtual host.

  3. This is a default HTTP server configuration:

     <VirtualHost *:80>
         ServerAdmin me@example.com
         DocumentRoot "C:/Apache24/htdocs"
         ServerName example.com:80
         ErrorLog "logs/example.com-error.log"
         CustomLog "logs/example.com-access.log" common
    
         ProxyRequests Off
         ProxyPreserveHost Off
     
         <Proxy *>
             Order deny,allow
             Allow from all
         </Proxy>
    
         <Location /sonarr>
             ProxyPass        http://localhost:8989/sonarr connectiontimeout=5 timeout=300
             ProxyPassReverse http://localhost:8989/sonarr
         </Location>
     
         <Location /couchpotato>
             ProxyPass        http://localhost:5050/couchpotato connectiontimeout=5 timeout=300
             ProxyPassReverse http://localhost:5050/couchpotato
         </Location>
     </VirtualHost>
    
  4. Save the file and execute httpd -t again to test your configuration syntax.

  5. Pull up your instance of Couchpotato and go to the general settings (show advanced settings) and set your Url base to couchpotato. Restart Couchpotato from the cog.

  6. Pull up your instance of Sonarr and go to Settings -> General -> Url Base and set it to /sonarr, or whatever you changed it to in your vhost. Restart Sonarr from System.

  7. Restart the Apache service.

  8. You should be able to access them respectively from yourdomain.com/sonarr and yourdomain.com/couchpotato.

@NavaneethVijay
Copy link

Thanks 👍 , this is very generic and works with no issues in windows 10

@sfardel
Copy link

sfardel commented May 13, 2020

Thanks, it very helpful and clear ✌

@acnaweb
Copy link

acnaweb commented Jul 15, 2020

Thanks! Very usefull for me.

@northerngosling
Copy link

Thanks, this was very helpful 👍

However I was getting the following error :

Invalid command 'Order', perhaps misspelled or defined by a module not included in the server configuration

As suggested by this post on stackoverflow, I had to replace :

<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

with :

<Proxy *>
    Require all granted
</Proxy>

@rahul7997
Copy link

Thanks! This is really helpful and simple to understand.

@EarthenLynx
Copy link

Thanks a load, I wish issues such as this one were more often so elegantly described.

@shadshack
Copy link

I want to add as well, that if you're wanting to use SSL, (assuming you have SSL set up in Apache already), you want to make the Vhost edits to Apache24\conf\extra\httpd-ssl.conf instead of Apache24\conf\extra\httpd-vhosts.conf. Took me a while to figure that out.

@kimboslice99
Copy link

For me just having the proxypass directive leaves websocket errors in the console, adding the below to the Location directive makes it work as it should

RewriteEngine On
RewriteCond %{HTTP:Connection} Upgrade [NC]
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteRule .* ws://localhost:8989%{REQUEST_URI} [P]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment