I figured out most of the issues. The system works as expected now. The
setup for *host A* should be:

<VirtualHost \*:80>
ServerName mydomain.com
ProxyPreserveHost On
RewriteEngine On
ProxyPass “/host1/“ "http://192.168.4.12/"; retry=0
RewriteCond %{HTTP_REFERER} “host1” [NC]
RewriteRule "^/index(.*)" “/host1/index$1" [R=301,L,E=nocache:1]
</VirtualHost>

The issue of not being logged in was cache on Firefox. Deleting cache
and set environment nocache in the rewriterule help.

Thanks everyone again,

D.

On 4 Oct 2022, at 23:50, Duke Nguyen wrote:

On 4 Oct 2022, at 22:03, Frank Gingras wrote:

A few comments first:

1) Try to avoid proxying inside a <Location> block, unless you have a
good
reason to. You have more control in the vhost context over the URI
paths.

Thanks for your comments. There are few reasons that I used
<Location>:

 - I wanted to have two proxies (with two subdomains, to two different
internal hosts) in the same block of mydomain.com; and I think putting
in two <Location> blocks would make it nicer;

 - I thought I would need to do something with mod_rewrite in order to
get what I wanted, because my URL gets rewritten after logging into
phpMyAdmin; putting these rewrite rules into two different <Location>
blocks will make them effective only with their corresponding block.
Please correct me if I am wrong.

2) Stop using the 2.2 authz directives, those have been deprecated
for
over
a decade

Thank you!

Now, your ProxyPassReverse is effectively:

ProxyPassReverse /host1/ http://192.168.4.12/

This means that if the backend issues a Location: header to something
other
than /host1/, you won't catch it. You need handle a more generic URI
scheme.

Yes. As mentioned above, I thought of using mod_rewrite as well. So
far
I tried:

 - using mod_rewrite on *host A*

<VirtualHost \*:80>
ServerName mydomain.com
ProxyPreserveHost on
<Location “/host1/“>
ProxyPass "[http://192.168.4.12/](http://192.168.4.12/)" retry=0
ProxyPassReverse "[http://192.168.4.12/](http://192.168.4.12/)"
RewriteEngine on
RewriteRule "^/index(.*)" “/host1/index$1" [R]
</Location>
</VirtualHost>

So now I am able to get **/host1/** stayed in URI after entering
phpMyAdmin credentials and getting redirection. However, the page stay
at log-in page instead of being actually logging in. It seems to me
some
parts of the URI are missing.

 - using mod_rewrite on *host B*

<VirtualHost \*:80>
DocumentRoot /var/www/html/phpMyAdmin
<Directory /var/www/html/phpMyAdmin>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerName 192.168.4.12
RewriteEngine on
RewriteRule "^/index(.*)" “/host1/index$1" [R]
ErrorLog logs/192.168.4.12\_81\_error\_log
CustomLog logs/192.168.4.12\_81\_access\_log common
</VirtualHost>

With this setup, I also got the **/host1/** stayed in URI, however all
the information after index.php are missing, only *index.php* got
redirected to the *host A* server.

Any advice?

Thanks,

D.

On Tue, 4 Oct 2022 at 06:02, Duke Nguyen <duke.li...@gmx.com> wrote:

Hello everyone,

I have an issue with the proxy and subdirectory on httpd. What I
wanted is
whenever clients access http://mydomain.com/host1/, the server *host
A*
will proxy it to *host B* internally, with the URI
http://mydomain.com/host1/ base unchanged. The httpd.conf on *host
A*
has
the following:

<VirtualHost *:80>
ServerName mydomain.com
ProxyPreserveHost on
<Location “/host1/“>
ProxyPass "http://192.168.4.12/"; retry=0
ProxyPassReverse "http://192.168.4.12/";
</Location>
</VirtualHost>

In the above httpd.conf, the internal IP 192.168.4.12 is the IP of
the *host
B*, and *host1* is just a *virtual* directory that I’d like to
name
it.
The *host B* is serving phpMyAdmin page, with the following
httpd.conf

<VirtualHost *:80>
DocumentRoot /var/www/html/phpMyAdmin
<Directory /var/www/html/phpMyAdmin>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerName 192.168.4.12
ErrorLog logs/192.168.4.12_81_error_log
CustomLog logs/192.168.4.12_81_access_log common
</VirtualHost>

Accessing phpMyAdmin on *host B* internally in my network, with the
URL
http://192.168.4.12/ work just fine, ie
http://192.168.4.12/index.php?abc
will show http://192.168.4.12/index.php?abc. However, when I tried
externally, it does not work as expected:

   - Accessing http://mydomain.com/host1/index.php works fine,
showing
   phpMyAdmin log in page
   - After entering username / password to log in, the URL on my
browser
   becomes http://mydomain.com/index.php?token=abc instead of
http://mydomain.com/host1/index.php?token=abc. Somehow the virtual
   subdirectory *host1* disappeared.

Please help!

Thanks

D.

Reply via email to