VirtualHost Same ServerName Different Directories

纵饮孤独 提交于 2019-12-06 03:43:05

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!