7

So I have the following two configurations:

On the one hand a backend server:

<VirtualHost *:80>
  ProxyPreserveHost On
  ServerName localhost
  ProxyPass /backend http://some_remote_ip:7000/backend
  ProxyPassReverse /backend http://some_remote_ip:7000/backend
  ProxyPassReverseCookiePath / /backend
  ProxyPassReverseCookieDomain some_remote_ip localhost
</VirtualHost>

And on the other hand a frontend server:

<VirtualHost *:80>
  ProxyPreserveHost On
  ServerName localhost
  ProxyPass  /excluded !
  ProxyPass / http://127.0.0.1:9000/
  ProxyPassReverse / http://127.0.0.1:9000/
</VirtualHost>

If I put those in a .conf file together, only the one that is written first, in the file, will work, so technically they are both correct.

So my question is how can I have multiple ProxyPass entries in the same VirtualHost configuration?

P.S.: I need to be able to access

  • the backend at localhost/backend
  • the frontend at localhost

1 Answer 1

8

The problem is that you have multiple VirtualHost sections for the same virtual host (localhost), so Apache will just pick one. If you want these configurations to work together, you have to put the ProxyPass directives in a single VirtualHost configuration:

<VirtualHost *:80>
  ProxyPreserveHost On
  ServerName localhost

  ProxyPass /backend http://some_remote_ip:7000/backend
  ProxyPassReverse /backend http://some_remote_ip:7000/backend
  ProxyPassReverseCookiePath / /backend
  ProxyPassReverseCookieDomain some_remote_ip localhost

  ProxyPass  /excluded !
  ProxyPass / http://127.0.0.1:9000/
  ProxyPassReverse / http://127.0.0.1:9000/
</VirtualHost>
1
  • Yes! I first tried to do it like that, but the reason it was not working, was because I needed to reverse the order - the backend needed to be first, because otherwise it was interfering with the routes of the frontend.
    – DrKaoliN
    Feb 15, 2017 at 10:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .