32

I've following virtual host configuration. The desired result is:

  1. If someone requests http://test.myserver.com/myapp, apache serves him from /var/www/myapp
  2. And if http://test.myserver.com/ is requested, apache redirects it to port 8069.

2nd is working but 1st is not. Can someone help please!

<VirtualHost *:80>
        ServerName test.myserver.com

        Alias /myapp /var/www/myapp
        <Directory /var/www/myapp>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                Allow from all
        </Directory>

        ProxyPass / http://localhost:8069/
        ProxyPassReverse / http://localhost:8069/

</VirtualHost>
user2436428
  • 1,653
  • 3
  • 17
  • 23

3 Answers3

53

This is how I was able to achive the desired outcome. Following is the working configuration where ProxyPassMatch ^/myapp ! did the trick and except the (server-address)/myapp, all the requests are being proxying to the other server which is open-erp running at port 8069:

<VirtualHost *:80>
        ServerName test.myserver.com

        Alias /myapp /var/www/myapp
        <Directory /var/www/myapp>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                Allow from all
        </Directory>

        ProxyPassMatch ^/myapp !
        ProxyPass / http://localhost:8069/
        ProxyPassReverse / http://localhost:8069/


  CustomLog /var/log/apache2/access.log common
  ErrorLog /var/log/apache2/error.log

</VirtualHost>
user2436428
  • 1,653
  • 3
  • 17
  • 23
  • 2
    Very useful in combination with let's encrypt verification of virtual hosts that use reverse proxying, but still want to use automatic verify, e. g. Alias /.well-known "C:/apache24/htdocs/.well-known" ... – AndyB Oct 27 '16 at 11:05
  • @AndiB The problem is that can't use ProxyPass. Only and that doesn't work with Alias. Looking for a solution… – ygoe Jul 23 '17 at 12:55
  • 1
    Here's a more thorough config recommendation: https://github.com/certbot/certbot/issues/2164 – The key is to use `ProxyPass /path /url` and not ` ProxyPass /url` as I did before. Now it works for me. – ygoe Jul 23 '17 at 13:10
  • @ygoe you're my hero today. – ruckc Dec 15 '17 at 17:46
22

Instead of using:ProxyPassMatch ^/myapp ! you could have simply added another ProxyPass directive before the one defining /, like this:

ProxyPass /myapp !
ProxyPass / http://localhost:8069/

Since ProxyPass respects precedence (the first match will be processed), it will correctly redirect to the directory instead of proxying.

Geoff Martin
  • 221
  • 2
  • 3
1

in case you have a RewriteCond (which is very likely when you run a proxy) this one will make you happy as well!

<Location /.well-known/acme-challenge/>
  RewriteEngine off
  ProxyPass !
</Location>
simUser
  • 756
  • 2
  • 7
  • 15