Linux – Reverse proxy for wildcard domains – apache linux

apache-2.2httpd.conflinuxreverse-proxywildcard-subdomain

I am trying to setup reverse proxy for wildcard domain, but my configuration don't simply work after I login to the application.

This server is running Apache aka httpd service with port 80, 443 on this server.

frafahadooappd5.de.cd.com

Domain is mapped to some other IP address like below,

 [dladmin@frasasdlappd2 ~]$ nslookup *.dev.cdsw.abc.intranet.cd.com --> wildcard webdomain
Server:         10.255.252.1
Address:        10.255.252.1#53

Non-authoritative answer:
*.dev.cdsw.abc.intranet.cd.com  canonical name = sdl-cdsw-dev.de.cd.com.
sdl-cdsw-dev.de.db.com  canonical name = frasasdlappd2.de.cd.com.
Name:   frasasdlappd2.de.cd.com
Address: 10.198.2.52

[dladmin@frasasdlappd2 ~]$ nslookup sdl-cdsw-dev.de.cd.com --> working like a variable as wildcard cant be directly mapped to normal
Server:         10.255.252.1
Address:        10.255.252.1#53

Non-authoritative answer:
sdl-cdsw-dev.de.cd.com  canonical name = frasasdlappd2.de.cd.com.
Name:   frasasdlappd2.de.cd.com
Address: 10.198.2.52

And, my configuration goes here like this,

NameVirtualHost *:443
<VirtualHost *:443>
        ServerName frafahadooappd5.de.cd.com:443
                ServerAlias *.dev.cdsw.intranet.cd.com


        AllowEncodedSlashes on
        #Options +Indexes +SymLinksIfOwnerMatch +FollowSymLinks
        #DirectoryIndex index.php index.html

        SSLEngine on
        SSLCertificateFile /opt/testlab/pki/publicCertificates/host_crt.pem
        SSLCertificateKeyFile /opt/testlab/pki/keystore/host_key.pem
        SSLCertificateChainFile /opt/testlab/pki/publicCertificates/chain_crt.pem
        SSLProxyEngine On

        ProxyPass /  https://dev.cdsw.abc.intranet.cd.com/
        ProxyPassReverse / https://dev.cdsw.abc.intranet.cd.com/
        ProxyPassReverseCookieDomain frafahadooappd3.de.cd.com frafahadooappd5.de.cd.com


                    RewriteEngine on
                        RewriteCond %{HTTPS_HOST} ^frafahadooappd5\.de\.cd\.com$
                        RewriteRule ^(.*)$                   "https\:\/\/frafahadooappd5\.de\.cd\.com\/$1" [R=301,L]

</VirtualHost>

When I navigate to the Reverse proxy URL,

Reverse proxy URL : https://frafahadooappd5.de.cd.com/ -> Application login page lands up with the proxied URL, even after the login to the application as expected, but there is a field named like projects inside the application webpage,
when I tap on that, it goes to the application URL
(https://dev.cdsw.abc.intranet.cd.com/login?next=%2Fvijay%2Ftest-dev),
which is not supposed to be the case rather than restricting itself to the reverse proxy URL.

Not sure, this rewrite condition is correct. Since this request is peculiar, I have furnished all the details. Please help me out with this.

Best Answer

It looks like you are expecting rewrite module to replace content, rewrite module changes http requests, it does not change content.

You can try and use substitute module, or reconfigure the application to dynamically assign links/assets with the host header or use relative links only.

Try something like...

AddOutputFilterByType SUBSTITUTE text/html
substitute "s|frafahadooappd5.de.cd.com|%{HTTPS_HOST}|inq"