0

I have installed Apache/2.4.56 (Debian), a noip URL and severals LXC containers. I need to access to the web apps inside the LXC containers:

example.com/app1 -> LXC container 1 (with Zend2)
example.com/app2 -> LXC container 2 (with Laravel 5)
example.com/app3 -> LXC container 3 (with Mattermost)
example.com/app4 -> LXC container 4 (with Plex)
example.com/app5 -> LXC container 5 (with Laravel 10)
example.com/app6 -> LXC container 5 (with Psono)
...
example.com/appN -> LXC container N

ip1: 10.0.3.101

ip2: 10.0.3.102

domain_url: http://example.com

1st approach:

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass             "/app1"       "http://ip1"
    ProxyPassReverse      "/app1"       "http://ip1"
</VirtualHost>

If I enter to example.com/app1 this send me to example.com/auth/index/index (I lost app1, this should be example.com/app1/auth/index/index). The ProxyPassReverse do not work?

2nd approach:

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass             "/app1"       "http://ip1"
    ProxyPassReverse      "/app1"       "http://ip1"
    ProxyPassReverse      "/app1"       "/"
</VirtualHost>

This work great! but I need more LXC containers.

3rd approach:

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass             "/app1"       "http://ip1"
    ProxyPassReverse      "/app1"       "http://ip1"
    ProxyPassReverse      "/app1"       "/"
    ProxyPass             "/app2"       "http://ip2"
    ProxyPassReverse      "/app2"       "http://ip2"
</VirtualHost>

example.com/app1 -> OK

The buttons was wrong, so I made some changes: The original action for the button was action="{{ route('login') }}" and it resolve as domain_url/login so I changed it to action="domain_url/app2/login"> and the result was: example.com/app2 -> welcome page -> example.com/app2/login (login page) -> example.com/app1/app2/login WRONG

4rd approach:

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass             "/app1"       "http://ip1"
    ProxyPassReverse      "/app1"       "http://ip1"
    ## WITH OUT THIS ##ProxyPassReverse      "/app1"        "/"
    ProxyPass             "/app2"       "http://ip2"
    ProxyPassReverse      "/app2"       "http://ip2"
</VirtualHost>

example.com/app1 -> example.com/auth/index/index WRONG

The buttons was wrong, so I made some changes: The original action for the button was action="{{ route('login') }}" and it resolve as domain_url/login so I changed it to action="domain_url/app2/login"> and the result was: example.com/app2 -> welcome page -> example.com/app2/login (login page) -> ```example.com/app2/# with so many css, js and images lost.

I think I do not have to use ProxyPassReverse "/app1" "/", so I continue that path but always got example.com/app1->example.com/auth/index/index```

This approach were:

<VirtualHost *:80>
    ProxyPreserveHost On
    ProxyPass             "/app1"       "http://ip1"
    ProxyPassReverse      "/app1"       "http://ip1"
    ProxyPass             "/app2"       "http://ip2"
    ProxyPassReverse      "/app2"       "http://ip2"

    ##HERE THE ATTEMPS .. serverfault do not like to spam the same text over and over again xD
</VirtualHost>

The attemps:

Attempt #1

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^10\.0\.3\.101$
    RewriteRule ^/(.*)$ domain_url/app1/$1 [P,L]
    RewriteCond %{HTTP_HOST} ^10\.0\.3\.102$
    RewriteRule ^/(.*)$ domain_url/app2/$1 [P,L]

Attempt #2

    RewriteEngine On

    RewriteCond %{RESPONSE} ^.*app1.*
    RewriteRule ^/app1/(.*)$ /app1/$1 [P,L]
    
    RewriteCond %{RESPONSE} ^.*app2.*
    RewriteRule ^/app2/(.*)$ /app2/$1 [P,L]

Attempt #3

    RewriteEngine On

    RewriteCond %{REQUEST_URI} ^/app1/
    RewriteRule ^/app1/(.*)$ domain_url/app1/$1 [P,L]
    
    RewriteCond %{REQUEST_URI} ^/app2/
    RewriteRule ^/app2/(.*)$ domain_url/app2/$1 [P,L]

Attempt #4

    ProxyHTMLEnable On
    ProxyHTMLExtended On

    ProxyHTMLURLMap http://ip1 domain_url/app1
    ProxyHTMLURLMap http://ip2 domain_url/app2

Attempt #5

    AddOutputFilterByType SUBSTITUTE text/html
    Substitute "s|http://10\.0\.3\.101|domain_url/app1|n"
    Substitute "s|http://10\.0\.3\.102|domain_url/app2|n"

Attempt #6

    RequestHeader edit Location ^http://10\.0\.3\.101(.*)$ domain_url/app1$1
    RequestHeader edit Location ^http://10\.0\.3\.101(.*)$ domain_url/app2$1

I need more ideas to test, someone can help me? please, any idea is welcome. I really appreciate your help. If this work, then I would like to configure HTTPS :D

P.S.: I prefer not to use ports, it is more formal to use /app1, etc.

2
  • 1
    Your first approach is correct. I bet that your app1 is redirecting the client. Use the CLI curl so that you can see the HTTP request and response including headers. Commented Nov 26, 2023 at 3:34
  • 1
    Indeed the first approach is correct, but that has problems when the application is deployed in the root of the backend server and uses absolute links to refer to content and resources. Such links don't get "corrected" by a the ProxyPassReverse mapping (that corrects only Location, Content-Location and URI headers and not response bodies). My answer in [this Q&A ](serverfault.com/questions/561892) is still mostly valid, despite being for apache 2.2 , the other answers provide direction on how to use ProxyHTMLURLMap which is more applicable for apache 2.4
    – HBruijn
    Commented Nov 27, 2023 at 14:50

0

You must log in to answer this question.

Browse other questions tagged .