0

I need to install a server with Apache 2.2 on Linux and I need to do two VirtualHosts differentiated by URI.

But with only one domain name and one ip address. And I can't use Alias.

I tried something like that but that doesn't work :

<VirtualHost *:80>
    DocumentRoot /var/www/app1
    ServerName localhost/app1
    ServerAlias www.localhost/app1

    <Directory /var/www/app1>
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/app2
    ServerName localhost/app2
    ServerAlias www.localhost/app2

    <Directory /var/www/app2>
        Allow from all
    </Directory>
</VirtualHost>

I need that cause I need to config an error log for each virtualhost.

I think, I can do perhaps something with the ServerPath but I don't know how.

Edit : Thank you a lot for the first answer, it's working :D

MyName
  • 103
  • 6

1 Answers1

3

What you could do is set up a reverse proxy to different virtual hosts listening only on loopback.

You would get in your www.localhost virtualhost:

<VirtualHost *:80>
    DocumentRoot /var/www/
    ServerName localhost
    ServerAlias www.localhost

    ProxyPassReverse /app1/ http://webapp1.local/
    ProxyPassReverse /app2/ http://webapp2.local/
</Virtualhost>

And create two virtualhosts for the apps:

<VirtualHost 127.0.0.1:80>
    DocumentRoot /var/www/app1
    ServerName webapp1.local

    <Directory /var/www/app1>
        Allow from all
    </Directory>
</Virtualhost>

<VirtualHost 127.0.0.1:80>
    DocumentRoot /var/www/app2
    ServerName webapp2.local

    <Directory /var/www/app2>
        Allow from all
    </Directory>
</Virtualhost>

Make sure to add webapp1.local and webapp2.local to your /etc/hosts file. Another possibility is apache-server-multiple-directories-different-error-logs

mtak
  • 561
  • 4
  • 11