title: How can I use apache2 on my Raspberry Pi to forward incoming subdomain requests to go to localhost ports running other applications?
body: <p>I'm new to networking and web development and am trying to create a home project for fun, to learn, and to have some capabilities I would like from a home server.  So far, I already own a domain name and have DDNS set up with Namecheap and port forwarding on my router so that incoming requests on port 80 get forwarded to my Pi on that port.  I can access a basic index.html page using mydomain.com and www.mydomain.com.</p>
  
  <p>I also want to be able to access some other applications running on my Pi remotely in the future.  Two I'm working on currently are Webmin and Shellinabox.  I can currently do this by going to mydomain.com:12321 and mydomain.com:4200 respectively.  However, I would like to have this set up in a cleaner way so I can instead go to webmin.mydomain.com and ssh.mydomain.com instead.  I am able to do that using Virtual Hosts and a redirect currently, but that changes the URL in the browser.</p>
  
  <p>As a more advanced solution, I'm trying to use mod_proxy so the URL in my browser still shows the URL I typed.  I've done some searching and think the best way to do this is using mod_proxy with virtual hosts, but I have not been able to get it to work.</p>
  
  <p>For starters, I don't think I understand how that works fully.  My basic understanding is that apache forwards an incoming request to another server and relays the reply back to the original requesting machine.  However, in testing, I tried to do this:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName ssh.mydomain.com
      ProxyPreserveHost On
      ProxyRequests Off
      &lt;Proxy *&gt;
              Order allow,deny
              Allow from all
      &lt;/Proxy&gt;
      ProxyPass / http://www.google.com
      ProxyPassReverse / http://www.google.com
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>My understanding would be that the Google homepage would show up when I navigated to ssh.mydomain.com, however I instead get a Google error page that says:</p>
  
  <blockquote>
    <ol start="404">
    <li>That’s an error.
    The requested URL / was not found on this server. That’s all we know.</li>
    </ol>
  </blockquote>
  
  <p>Clearly I'm misunderstanding this.  Prior to this testing, I had that block of code configured like this:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName ssh.mydomain.com
      ProxyPreserveHost On
      ProxyRequests Off
      &lt;Proxy *&gt;
              Order allow,deny
              Allow from all
      &lt;/Proxy&gt;
      ProxyPass / http://localhost:4200
      ProxyPassReverse / http://localhost:4200
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>I've also tried 0.0.0.0 and 127.0.0.1 instead of localhost, so I don't believe that's the issue.  When I have it set up as shown above and navigate to that URL, I get this in Safari:</p>
  
  <blockquote>
    <p>Safari Can't Connect to the Server
    Safari can't open the page "<a href="https://ssh.mydomain.com" rel="nofollow noreferrer">https://ssh.mydomain.com</a>" because Safari can't connect to the server "ssh.mydomain.com".</p>
  </blockquote>
  
  <p>I can't help but wonder if the https is causing some issue.  I'm not typing it into my browser, but it is shown in the page it's trying to connect to.  I'm just not sure at this point.  I could make it functional, sure, but I want to learn how to do it the way I'm trying here.  I'm open to other ideas that would keep the browser URL instead of redirects if there are other ways that don't use mod_proxy, but from other places I've read, this seems to be the way.  Thanks in advance for your help.</p>