Lucas Beier
Lucas Beier

Reputation: 631

Multiple proxy reverse for one Virtual Host

I have a server which we use to test some services. It's basically a server where devs can run some containers in order to run some tests.

What I'm trying to do is proxy reverse some url patterns into some containers.

For example, this is what I have now:

<VirtualHost *:80>
       ServerName dev.server.com

       RewriteEngine On

       RewriteRule (.*) https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<VirtualHost *:443>
       ServerName dev.server.com

       <--- certificates and log configs --->

       SetEnv proxy-nokeepalive 1
       ProxyRequests     On
       ProxyPreserveHost On
       RewriteEngine     On

       ProxyPass /appOne http://localhost:9999/
       ProxyPassReverse /appOne http://localhost:9999/

       ProxyPass /appTwo http://localhost:9000/
       ProxyPassReverse /appTwo http://localhost:9000/

       ProxyPass / http://localhost:3000/
       ProxyPassReverse / http://localhost:3000/
</VirtualHost>

But when I access https://dev.server.com/appOne, it access the app deployed on port 3000 instead of the one deployed on port 9999.

I've never configured Apache before, so I'm struggling to understand all the concepts. Is this possible? If yes, where is my mistake?

Upvotes: 0

Views: 5522

Answers (1)

larsks
larsks

Reputation: 311238

What you want to do is certainly possible. In fact, using a configuration substantially identical to what you've posted, I can't reproduce the problems you've described -- everything seems to work as you want.

I've put a complete example here as a docker-compose application; it starts up four containers:

  • One apache instance acting as a frontend with the ProxyPass directives
  • Three apache instances acting as backends listening on the various ports

The mod_proxy configuration is identical to what you've shown:

ProxyPass /appOne http://localhost:9999/
ProxyPassReverse /appOne http://localhost:9999/

ProxyPass /appTwo http://localhost:9000/
ProxyPassReverse /appTwo http://localhost:9000/

ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/

The only difference of note is that I haven't configured an SSL context for my frontend server. Other than the two examples you've shown in your question, are there any other VirtualHost blocks in your configuration (in particular, other virtual hosts configured on port 443)?

Upvotes: 1

Related Questions