user5839 user5839 - 2 months ago 29
Apache Configuration Question

Virtual Host on subdomain only on TomCat httpd.config

I have a virtual host

<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName gms.example.co
ProxyPass / http://localhost:9081/
ProxyPassReverse / http://localhost:9081/
</VirtualHost>


That picks up all http requests i.e. both gms.example.co and example.co get forwarded to localhost:9081

How do I only forward gms.example.co to localhost:9081 and example.co to localhost ?

EDIT

<VirtualHost *:80>
ServerName example.co
DocumentRoot C:/workspace/html/
</VirtualHost>

<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName gms.example.co
ProxyPass / http://localhost:9081/
ProxyPassReverse / http://localhost:9081/
</VirtualHost>


At the end of httpd proxy.

The second works, the first one doesn't.


Internal Server Error


I also get this on localhost so I assume they're related

And this error in the logs

[Tue Sep 13 19:38:38.081314 2016] [core:alert] [pid 24988:tid 1112] [client 127.0.0.1:60053] C:/workspace/html/.htaccess: Unrecognized header format %

Answer

Create another VHost configuration, with the ServerName directive set to example.co or www.example.co. In your server's root config file, Include the newly created VHost config too.

<VirtualHost *:80> 
  ServerName example.co
  ServerAlias www.example.co
  DocumentRoot /path/to/your/localhost
</VirtualHost>

save the above as 000-root.conf (the 000 is so that this gets higher precedence).