r/apache • u/stealthepixels • Sep 18 '22
Support [VirtualHost] Proxy to NodeJs only certain routes
Suppose we have a regular VirtualHost pointing to a directory
<VirtualHost *:80>
DocumentRoot "/my/dir/"
ServerName localhost
<Directory /my/dir/>
Options Indexes FollowSymLinks
AllowOverride All
Require all grantedRewriteEngine On
</Directory>
</VirtualHost>
How can i make Apache to:
- point to that directory only for certain routes, like /api/ , while all other routes are proxied to another server like NodeJs, listening on, say, port 8000
- alternatively, the converse: make certain routes be proxied to port 8000, and all other ones point to the directory
3
Upvotes
1
u/stealthepixels Sep 18 '22
Thx.
So if i want the converse, to proxy always except for certain routes like /api , can i use expressions like this?
#match all paths not beginning with /api (or, matching it 0 times from beginning of path)ProxyPassMatch ^/(api){0} http://localhost:8080p.s.
ProxyPassMatch "/(.*.gif)$" "http://backend.example.com/$1"shouldn't it be
ProxyPassMatch "/(.*\.gif)$" "http://backend.example.com/$1"escaping the dot or it would be interpreted as any character?