Apache crash if I try to use ProxyPass on localhost to expose different services as subdomain

I have the following directory structure for multiple websites and services

/var/www/html/site1
/var/www/html/site2
/var/www/html/site3
/var/www/html/serv1
/var/www/html/serv2

site1 folder hosts a website site1domain.com I want to expose the webapp services hosted in serv1 and serv2 folders in order to show them as

service1.site1domain.com
service2.site1domain.com

So I have tried to configured the virtual host in site1domain.conf file in this way

<VirtualHost *:80>
    ServerName site1domain.com
    ServerAlias www.site1domain.com
    DocumentRoot /var/www/html/site1
    <Directory /var/www/html/site1>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerName service1.site1domain.com
    ProxyPreserveHost On
    ProxyRequest Off
    ProxyPass        "/" "localhost/serv1"
    ProxyPassReverse "/" "localhost/serv1"
</VirtualHost>

<VirtualHost *:80>
     ServerName service2.site1domain.com
     ProxyPreserveHost On
     ProxyRequest Off
     ProxyPass        "/" "localhost/serv2"
     ProxyPassReverse "/" "localhost/serv2"
</VirtualHost>

But the virtual host code blocks related to services cause a crash of the server: exit with error code 1.

Could someone help me to understand how to configure them properly?


How about just:

<VirtualHost *:80>
    ServerName service1.site1domain.com
    DocumentRoot /var/www/html/serv1
</VirtualHost>

<VirtualHost *:80>
    ServerName service2.site1domain.com
    DocumentRoot /var/www/html/serv2
</VirtualHost>

No mod_proxy needed.


The error is caused by your ProxyPass and ProxyPassReverse directives not having the scheme part of the URL. The correct syntax would be e.g.

ProxyPass "/" "http://localhost/serv1" 
ProxyPassReverse "/" "http://localhost/serv1"

However, Andrew is correct in that reverse proxy isn't required nor best technology for this use case.