tozlu
tozlu

Reputation: 4865

VirtualHost Same ServerName Different Directories

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?

Upvotes: 3

Views: 1168

Answers (2)

rluta
rluta

Reputation: 6917

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.

Upvotes: 3

Daniel Scott
Daniel Scott

Reputation: 7971

It depends a little on whether your own app is hosted on the apache server itself, or it's proxied to another server/process.

If it's on the apache server itself, then just put 'myapp' into the document root. Then you need to remove your ProxyPass line and replace it with a locationmatch block

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

    <LocationMatch "^(?!/myapp)">
        ProxyPassMatch balancer://balancer://redminecluster
    </LocationMatch>

    ProxyPassReverse / balancer://redminecluster

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

</VirtualHost>

So, the strategy is to forward everything which doesn't match /myapp to your existing redmine application. Everything matching /myapp will go to the document root. If your own app is proxied, then you need another locationmatch block which proxies /myapp to the correct location.

Upvotes: 2

Related Questions