Guerric P
Guerric P

Reputation: 31805

How to ProxyPass if the request doesn't correspond to a file

I'm trying to implement the following behavior: If the request corresponds to a file in /var/www/html, then serve it, else, ProxyPass to a different hostname and port. I am aware of the RewriteCond directive and that we can exclude some path from a ProxyPass but that doesn't help me achieve what I want.

At the moment my config looks like this:

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<VirtualHost *:80> 
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass /backend/ http://server:8080/backend/
    ProxyPassReverse /backend/ http://server:8080/backend/
    ProxyPass / http://client:4000/
    ProxyPassReverse / http://client:4000/
</VirtualHost>

Upvotes: 0

Views: 61

Answers (1)

Dusan Bajic
Dusan Bajic

Reputation: 10849

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

<VirtualHost *:80>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /backend/ http://server:8080%{REQUEST_URI} [P,L]
ProxyPassReverse /backend/ http://server:8080/backend/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule / http://client:4000%{REQUEST_URI} [P,L]
ProxyPassReverse / http://client:4000/
</VirtualHost>

Upvotes: 1

Related Questions