Apache hostname based HTTP proxy

I used to configure HTTP Apache correctly to redirect incoming HTTP requests to port 80 to a Tomcat instance running on port 8080. However, now I am in a situation where I need to be able to proxy incoming requests to port 80 or Tomcat @ 8080, or another process @ 9000, depending on the host name. The following is a snippet of my attempt to configure my Apache configuration to handle this case:

<VirtualHost *:80> ServerName hostname1 ProxyPreserveHost On ProxyPass / http://hostname1:8080/ ProxyPassReverse / http://hostname1:8080/ </VirtualHost> <VirtualHost *:80> ServerName hostname2 ProxyPreserveHost On ProxyPass / http://hostname2:9000/ ProxyPassReverse / http://hostname2:9000/ </VirtualHost> 

Now, when you request either host_name_1 or host_name2 , I get an instant 500, apparently due to the fact that mod_proxy does not find any suitable rules for proxying the request:

 [Fri Feb 08 06:41:01 2013] [warn] proxy: No protocol handler was valid for the URL /. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule. 

Please note that Tomcat does not accept incoming requests and therefore does not display a log

For common sense, I checked that I can really access these two resources individually in their respective ports, that is, I can access hostname1 using hostname 1: 8080 and hostname2 using hostname2 :. 9000

Are there any flaws here to help me set this up correctly?

Also, are there more efficient ways to manage this, perhaps in a more reasonable way?

Thanks for the help!

+7
source share
3 answers

The answer seemed to be the wrong configuration of a single module, namely mod_proxy_http. I came up with the following answer to a server that helped me because it was knocked over by the message β€œproxy: no protocol handler was valid for the URL” in the Apache HTTP error logs: https://serverfault.com/questions/242650/setting-up -a-basic-mod-proxy-virtual-host

+4
source

If you want to configure name-based virtual hosts, add the NameVirtualHost directive.

Add ServerName and DocumentRoot to each VirtualHost .

Example:

 NameVirtualHost *:80 <VirtualHost *:80> ServerName hostname1 DocumentRoot /www/hostname1 ProxyPreserveHost On ProxyPass / http://hostname1:8080/ ProxyPassReverse / http://hostname1:8080/ </VirtualHost> <VirtualHost *:80> ServerName hostname2 DocumentRoot /www/hostname2 ProxyPreserveHost On ProxyPass / http://hostname2:9000/ ProxyPassReverse / http://hostname2:9000/ </VirtualHost> 
+1
source

If you have an error log:

If you are using the mod_proxy DSO version, make sure that the proxy server submodules are included in the configuration using LoadModule.

Make this command:

 a2enmod proxy_http 
+1
source

All Articles