{"id":300,"date":"2019-04-16T09:51:09","date_gmt":"2019-04-15T21:51:09","guid":{"rendered":"https:\/\/www.berserkir.net\/wordpress\/?p=300"},"modified":"2026-01-13T08:40:35","modified_gmt":"2026-01-12T20:40:35","slug":"reverse-proxy-with-apache","status":"publish","type":"post","link":"https:\/\/www.berserkir.net\/wordpress\/reverse-proxy-with-apache\/","title":{"rendered":"Reverse Proxy (with Apache)"},"content":{"rendered":"\n<p>I did a little write-up on how I achieved <a href=\"https:\/\/www.berserkir.net\/wordpress\/reverse-proxy-with-iis\/\" title=\"Reverse Proxy (with IIS)\">reverse proxy nirvana with IIS<\/a> a while ago now. It made things a lot nicer for me. Like, <em>a lot.<\/em><\/p>\n\n\n\n<p>I have a few friends\/colleagues\/acquaintances who run Apache (I run IIS in my homelab environment, that&#8217;s the only reason I went with it), so I figured I&#8217;d look into how I can help them do the same thing (only a little different).<\/p>\n\n\n\n<!--more-->\n\n\n\n<h3 class=\"wp-block-heading\">Installing the proxy components<\/h3>\n\n\n\n<p>Firstly, you need to install the components to allow Apache to actually route things. It&#8217;s fairly straightforward to do, and simply requires you have root access to the shell on your server.<br><br>There are two main components that you need: <br>libapache2-mod-proxy-html and libxml2-dev. <br>Install them with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install -y libapache2-mod-proxy-html libxml2-dev<\/code><\/pre>\n\n\n\n<p>You&#8217;ll then need to activate them. &#8216;a2enmod&#8217; comes into play here<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo a2enmod proxy\nsudo a2enmod proxy_http\nsudo a2enmod proxy_ajp\nsudo a2enmod rewrite\nsudo a2enmod deflate\nsudo a2enmod headers\nsudo a2enmod proxy_balancer\nsudo a2enmod proxy_connect\nsudo a2enmod proxy_html<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring the proxy settings<\/h3>\n\n\n\n<p>With the modules activated we can start to actually configure the reverse proxy settings.<br>These settings are done in the config file for your &#8216;virtualhost&#8217;. (which is what defines each site that Apache is serving). Usually these are in <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">\/etc\/apache2\/sites-enabled<\/code> &#8211; the files in there should simply be symlinks to their counterparts in <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">\/etc\/apache2\/sites-available<\/code>.<br>Pick the config file for the site you want to set up sub-proxy for. Edit it using:<br><code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">sudo nano -w \/etc\/apache2\/sites-enabled\/%site-config.conf%<\/code><\/p>\n\n\n\n<p>All the config needs to be put inside the virtualhost section of the config &#8211; inside the section enclosed with <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">&lt;VirtualHost><em>content<\/em>&lt;VirtualHost \/><\/code> tags. <br>Add this line below the DocumentRoot entry (this tells it to pass the actual source through the reverse proxy to the proxied application):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ProxyPreserveHost On<\/code><\/pre>\n\n\n\n<p>It can be a good idea to add comments to things that you edit so you can remember why you edited it, if you&#8217;re anything like me. Remember to put a &#8220;#&#8221; in front of it to mark it as a comment instead of actual code.<\/p>\n\n\n\n<p>Near the bottom of the config, I put the actual &#8216;proxypass&#8217; entries into place (just before the final virtualhost close tag). They work elsewhere in the config &#8211; I just find it easier to put custom config near the bottom of config files where possible, so it&#8217;s consistently easy to find.<br>Add in entries for each thing you want to proxy. Make sure the item you are proxying has a baseurl configured &#8211; that way it doesn&#8217;t panic when the url passed to it is &#8216;application\/base\/argument&#8217;, rather than the expected &#8216;application\/argument&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Sonarr\nProxyPass \/sonarr http:\/\/internal.ip.of.host:8989\/sonarr\nProxyPassReverse \/sonarr http:\/\/internal.ip.of.host:8989\/sonarr\n# Radarr\nProxyPass \/radarr http:\/\/internal.ip.of.host:7878\/radarr\nProxyPassReverse \/radarr http:\/\/internal.ip.of.host:7878\/radarr<\/code><\/pre>\n\n\n\n<p>Save the config using CTRL+O (&#8216;o&#8217; for &#8216;overwrite&#8217; with nano)<br>Answer &#8216;yes&#8217; if it prompts.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Activating the changes<\/h3>\n\n\n\n<p>To activate the new proxy settings, restart apache.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>service apache2 restart<\/code><\/pre>\n\n\n\n<p>This should allow you to access the software on &#8220;http:\/\/server\/sonarr&#8221;, &#8220;http:\/\/server\/radarr&#8221; etc &#8211; rather than remembering the port for each application, and forwarding ports for each as well. It also means you can set up an SSL connection to secure it &#8211; but that&#8217;s a topic for another writeup (I use <a href=\"https:\/\/certbot.eff.org\/\" title=\"\">Certbot <\/a>for it).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I did a little write-up on how I achieved reverse proxy nirvana with IIS a while ago now. It made things a lot nicer for me. Like, a lot. I have a few friends\/colleagues\/acquaintances who run Apache (I run IIS in my homelab environment, that&#8217;s the only reason I went with it), so I figured &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/www.berserkir.net\/wordpress\/reverse-proxy-with-apache\/\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[80,5,41,16,78],"tags":[79,47,56,53,13,26,45,48],"class_list":["post-300","post","type-post","status-publish","format-standard","hentry","category-apache","category-helpful-hints","category-servers","category-software","category-web-systems","tag-apache","tag-open-source","tag-ports","tag-reverse-proxy","tag-server","tag-software","tag-useful","tag-web-page","item-wrap"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.berserkir.net\/wordpress\/wp-json\/wp\/v2\/posts\/300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.berserkir.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.berserkir.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.berserkir.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.berserkir.net\/wordpress\/wp-json\/wp\/v2\/comments?post=300"}],"version-history":[{"count":10,"href":"https:\/\/www.berserkir.net\/wordpress\/wp-json\/wp\/v2\/posts\/300\/revisions"}],"predecessor-version":[{"id":422,"href":"https:\/\/www.berserkir.net\/wordpress\/wp-json\/wp\/v2\/posts\/300\/revisions\/422"}],"wp:attachment":[{"href":"https:\/\/www.berserkir.net\/wordpress\/wp-json\/wp\/v2\/media?parent=300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.berserkir.net\/wordpress\/wp-json\/wp\/v2\/categories?post=300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.berserkir.net\/wordpress\/wp-json\/wp\/v2\/tags?post=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}