Apache virtual host config not working for one hosts

apache-2.2configurationvirtualhost

I am new to configuring Apache. I have two applications that I need to run locally, they are running on different servers – one on jboss and the other on Jetty. Now both of them use the same Apache server for serving static files.

I resolved the issues with jboss and jetty server for http port (8080) and ajp port (8009). Both the servers startup without port conflicts. Then came the configuration part for Apache.

The httpd.conf has the definition for server1 (app1 on jboss), so I added a reference to a vhostsfile and put in the configuration for server2(app2 on jetty). Problem is if I have the reference to the vhostsfile, app2 works fine but app1 never gets resolved by Apache – "The requested URL /us/en_us was not found on this server"

At first I thought perhaps I should put both server's definition in vhosts file and so I did. Put in definition for server1 below server2 but – app1 still did not load while app2 loaded as before. Requests to app1 were showing up access logs for app2.

Then in the vhosts file, I swapped the definitions i.e put server1's definition above server2, now both the apps did not load in the browser.

I hope I am not too confusing here. App1 with server1's definition only (no vhost) works. Upon adding server2's definition (in vhosts), app1 stops working but app2 does work. Also, which ever server's definition is above the other in vhosts file was intercepting requests to both the apps.

NameVirtualHost *:80

    <VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.com
    DocumentRoot "C:/env/local/cust/httpd/docs/dummy-host.com"
    ServerName dummy-host.com
    ServerAlias www.dummy-host.com
    ErrorLog "logs/dummy-host.com-error.log"
    CustomLog "logs/dummy-host.com-access.log" common
</VirtualHost>

<VirtualHost app2.local.com:80>
    ServerAdmin app2@local.com
    DocumentRoot "C:/app2"
    ServerName app2.local.com
    ErrorLog "logs/store-error.log"
    CustomLog "logs/store-access.log" common    
    <Directory "C:/app2">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost app1.local.com:80>
   ServerAdmin app1@local.com
   DocumentRoot "C:/workspace/app1"
   ServerName app1.local.com
   ErrorLog "logs/app1-error.log"
   CustomLog "logs/app1-access.log" common

   <Directory "C:/app1/">
       Options Indexes FollowSymLinks
       AllowOverride all
       Order allow,deny
       Allow from all
   </Directory>
</VirtualHost>

Best Answer

You're breaking name-based virtual hosting by having the hostnames in the <VirtualHost> definitions.

Change <VirtualHost app1.local.com:80> and <VirtualHost app2.local.com:80> to <VirtualHost *:80>, and make sure you have a NameVirtualHost *:80 somewhere in your config.

Related Topic