0

What I have now is several virtual hosts that are identified by subdomain, and then proxied to a server like so:

<VirtualHost *:80>
ProxyPass / http://192.168.1.1/
ProxyPassReverse / http://192.168.1.1/
ServerName sub1.example.com
</VirtualHost>

<VirtualHost *:80>
ProxyPass / http://192.168.1.2/
ProxyPassReverse / http://192.168.1.2/
ServerName sub2.example.com
</VirtualHost>

What I want to have instead is for apache to proxy based on example.com/sub1, example.com/sub2, etc.

Nothing I have experimented with seems to work as well as the subdomains. I've tried using the Alias directive, Location blocks, etc. but it keeps rewriting the URLs to my browser which of course cannot reach the backend machines. How can this be done correctly?

1

It's not clear what you have tried. The first thing I would try is a simple proxypass of /subN to a backend machine

<VirtualHost *:80>
    ProxyPass /sub1 http://192.168.1.1/
    ProxyPassReverse /sub1 http://192.168.1.1/
    ProxyPass /sub2 http://192.168.1.2/
    ProxyPassReverse /sub2 http://192.168.1.2/
    ServerName example.com
</VirtualHost>
  • sigh, tried to make up for an odd down-vote here. – covener Jan 22 '16 at 18:37
0

It's possible, and basic/common, to choose a backend based on the path in the URL.

It's a bit more rare to make that truly directory based because normally proxying happens before requests are mapped anywhere on disk -- but it can be done with mod_rewrite and the [P] flag.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.