Wednesday, August 31, 2022

[SOLVED] VirtualHost Same ServerName Different Directories

Issue

I have a running production website assigned to a host (redmine application). I need to add a new application to the same host as a sub-directory.

This is the current virtualhost configuration for redmine application which runs at base folder of host.

<VirtualHost *:80>
    ServerName redmine.hostname.com
    DocumentRoot "C:/BitNami/redmine-2.5.1-1/apps/redmine/htdocs/public/"

    RewriteEngine On
    RewriteRule ^/(.*)$ balancer://redminecluster%{REQUEST_URI} [P,QSA]

    ProxyPass / balancer://redminecluster
    ProxyPassReverse / balancer://redminecluster

    <Proxy balancer://redminecluster>
       BalancerMember http://127.0.0.1:3001
       BalancerMember http://127.0.0.1:3002
    </Proxy>

</VirtualHost>

So this application already runs at redmine.hostname.com. I want to add my own application and i want it to run at redmine.hostname.com/myapp/.

Whatever i did, i couldn't achieve this. I must not change the path of redmine, i must add new app to same virtualhost. There are no open ports other than 80, so i must make it run at redmine.hostname.com/myapp/

Basically, the redmine application must reply all requests that do not start with redmine.hostname.com/myapp/. My App should reply all requests that start with redmine.hostname.com/myapp.

What settings should i use?


Solution

If your application /myapp is located is c:/myappdir, the easiest way to configure apache to do what you want is to use this configuration:

<VirtualHost *:80>
    ServerName redmine.hostname.com
    DocumentRoot "C:/BitNami/redmine-2.5.1-1/apps/redmine/htdocs/public/"

    Alias /myapp "c:/myappdir"
    ProxyPass /myapp !

    ProxyPass / balancer://redminecluster/
    ProxyPassReverse / balancer://redminecluster/

    <Proxy balancer://redminecluster>
       BalancerMember http://127.0.0.1:3001
       BalancerMember http://127.0.0.1:3002
    </Proxy>

</VirtualHost>

Using an exclamation point as target for ProxyPass will exclude /myapp from the proxy configuration as documented here. Additionally you don't need a special RewriteRule since you don't modify the requests to redmine, ProxyPass should be enough.



Answered By - rluta
Answer Checked By - Gilberto Lyons (WPSolving Admin)