Two applications on Apache server with URI

I need to install a server with Apache 2.2 on Linux, and I need to make two virtual hosts differentiated by URI.

But with only one domain name and one IP address. And I can not use an alias.

I tried something like this, but this does not 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>
+4
source share
2 answers

Thanks, the first answer is here, it works: https://serverfault.com/questions/588841/two-apps-on-apache-server-with-uri

I will answer here if one day the link does not work:

What you can do is set up a reverse proxy server for different virtual hosts listening only on the loop.

www.localhost:

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

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

:

<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>

webapp1.local webapp2.local /etc/hosts.

0

IP-, Apache, , . VirtualHosts.

, , DocumentRoot:

ServerName whatever-your-domain.is

DocumentRoot /var/www

<Directory /var/www/app1>
    Order allow,deny
    Allow from all
</Directory>

<Directory /var/www/app2>
    Order allow,deny
    Allow from all
</Directory>

:

" " : /var/www, http://whatever-your-domain.is/

-2

Source: https://habr.com/ru/post/1535944/


All Articles