title: Apache Reverse Proxy For Specific Subdomain
body: <p>I'm have a an Apache HTTP server that has a reverse proxy to a tomcat server. However, I only want the reverse proxy to happen when the client uses the subdomain www. This is because I want to use other subdomains to point to other applications, such as email.</p>
  
  <p>e.g. www.example.com will go display the apache tomcat webapp.</p>
  
  <p>The way to do this, I presume, is to configure my DNS so that every subdomain I use will point to my server. Right now, in addition to www, that is server.example.com and posfixadmin.example.com. However, the issue is that all my subdomains end up pointing to tomcat.</p>
  
  <p>So when I try to visit postfixadmin.example.com/setup.php to set up postfixadmin through its web setup, it ends up taking me to my tomcat webapp's 404.</p>
  
  <p>Here is my virtualhost configuration:</p>
  
  <pre><code>&lt;VirtualHost www.example.com:80&gt;
      ServerName http://www.example.com
      ProxyPass / http://localhost:8080
      ProxyPassReverse / http://localhost:8080
  &lt;/Virtualhost&gt;
  
  &lt;VirtualHost server.example.com:80&gt;
      ServerName server.example.com
      DocumentRoot /var/www/html/
      RewriteEngine on
      RewriteCond %{SERVER_NAME} =server.example.com
      RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} {END,NE,R=permanent}
  &lt;/VirtualHost&gt;
  
  &lt;VirtualHost postfixadmin.example.com:80&gt;
      ServerName postfixadmin.example.com
      DocumentRoot /var/www/postfixadmin/public
  
      ErrorLog /var/log/httpd/postfixadmin_error.log
      CustomLog /var/log/httpd/postfixadmin_access.log combined
  
      &lt;Directory /&gt;
          Options FollowSymLinks
          AllowOverride All
      &lt;/Directory&gt;
  
      &lt;Directory /var/www/postfixadmin/public&gt;
         Options FollowSymLinks MultiViews
         AllowOverride All
         Order allow,deny
         allow from all
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  
  </code></pre>
  
  <p><strong>EDIT</strong>
  It looks like the proxy conf file doesn't do anything (??). I decided to experiment around and change the first virtualhost servername to the following:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName abcd.example.com
      ProxyPass / http://localhost:8080
      ProxyPassReverse / http://localhost:8080
  &lt;/Virtualhost&gt;
  </code></pre>
  
  <p>Then, I restarted and reloaded Apache...But for some reason, going to www.example.com STILL took me to the tomcat webapp! Does anyone know what drives this?</p>