Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse proxy two servers based on subpath

apache question. Must be something simple, but I'm failing.

I'm trying to configure apache as a reverse proxy to two servers behind it. The tricky part is that the only difference to register the proxy rule is a subpath.

My idea is:

mydomain.com -> localhost:8083
mydomain.com/api -> localhost:8080/api

Currently my config is this:

<VirtualHost *:80>
        ProxyPreserveHost On
        ProxyRequests Off
        ServerName mydomain.com
        ServerAlias www.mydomain.com

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        ProxyPass / http://localhost:8083/
        ProxyPassReverse / http://localhost:8083/

        ProxyPass /api http://localhost:8080/api #already tried with slashes on both first and second parameters
        ProxyPassReverse /api http://localhost:8080/api #already tried with slashes on both first and second parameters

</VirtualHost>

But the /api isn't working, it keep sending the request to 8083. Any ideas on why?

thanks for the attention

like image 473
Allan Vital Avatar asked Mar 13 '26 16:03

Allan Vital


1 Answers

Try doing the '/api' ProxyPass+ProxyPassReverse before the '/' one. I strongly suspect '/' is acting as a catchall and you're never getting to the '/api' case. This would explain why you always go to 8083, which is the '/' case.

<VirtualHost *:80>
        ProxyPreserveHost On
        ProxyRequests Off
        ServerName mydomain.com
        ServerAlias www.mydomain.com

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        ProxyPass /api http://localhost:8080/api #already tried with slashes on both first and second parameters
        ProxyPassReverse /api http://localhost:8080/api #already tried with slashes on both first and second parameters

        # do this last...
        ProxyPass / http://localhost:8083/
        ProxyPassReverse / http://localhost:8083/


</VirtualHost>
like image 75
obscurite Avatar answered Mar 16 '26 21:03

obscurite



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!