Apache port to subfolder reverse proxy

Config file location

RHEL based distributions

httpd.conf

Debian

sites-available/default

Updating & Installing

Update package lists:

apt-get update

Install Apache2 with mod_proxy:

sudo apt-get install libapache2-mod-proxy-html

Install libxml2 module:

apt-get install libxml2-dev

On /etc/apache2/apache2.conf add below code

LoadModule  proxy_module         /usr/lib/apache2/modules/mod_proxy.so
LoadModule  proxy_http_module    /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule  headers_module       /usr/lib/apache2/modules/mod_headers.so
LoadModule  deflate_module       /usr/lib/apache2/modules/mod_deflate.so
LoadFile    /usr/lib/x86_64-linux-gnu/libxml2.so

Method 1

Add a sample reverse proxy configuration to the same file /etc/apache2/apache2.conf

ProxyPass /subfolder http://127.0.0.1:9999/
ProxyPassReverse /subfolder http://127.0.0.1:9999/

Restart Apache2:

systemctl restart apache2

Method 2

Config file

<VirtualHost *:80>

        ServerName example.com
        ServerAlias www.example.com
        ServerAdmin example@example.com

       <Location /app1>
             ProxyPass http://localhost:4000/
      </Location>

       <Location /app2>
             ProxyPass http://localhost:4001/
      </Location>

</VirtualHost>