-1

I want that when i hit URL A, it should serve content from URL B but the URL on the address bar should keep pointing to URL A only.

URL A: http://apps.company.com/lab
URL B: http://svrdev-73:6020

To try this out, in hosts file, i have configured the following:

172.16.0.73         apps.company.com

I am using Windows server 2016. Application B and Apache (ver. 2.4), both are running on same Windows server. I found that ProxyPass and ProxyPassReverse might help.

Added the following lines at the end of httpd.conf file:

ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode

<Proxy http://svrdev-73:6020/*>
  Order deny,allow
  Allow from all
</Proxy>

ProxyPass         /lab  http://svrdev-73:6020 nocanon
ProxyPassReverse  /lab  http://svrdev-73:6020

After (mis)configuring, when i try hitting URL A, though it takes me to the login page that comes up when i directly access URL B, but when i login, it doesn't display anything. In console section of my browser, i see the following:

Failed to load resource: the server responded with a status of 404 (Not Found) main.00e8fde0.css:1
Failed to load resource: the server responded with a status of 404 (Not Found) main.aa149470.js:1

When i check the Apache log, i see this:

[Sun Sep 23 12:35:54.949711 2018] [core:info] [pid 20708:tid 1072] [client 172.16.0.73:60914] AH00128: File does not exist: C:/apache24/htdocs/static/css/main.00e8fde0.css, referer: http://apps.company.com/lab
[Sun Sep 23 12:35:54.949711 2018] [authz_core:debug] [pid 20708:tid 1076] mod_authz_core.c(817): [client 172.16.0.73:60913] AH01626: authorization result of <RequireAny>: granted, referer: http://apps.company.com/lab

From the above i see that it is looking for file in the default DocumentRoot directory (i.e., "${SRVROOT}/htdocs") however, my application code (URL B) is in Tomcat at c:\app-tomcat\webapps\ROOT\ directory. I also tried changing the DocumentRoot dir path to c:/app-tomcat/webapps/ROOT where index.html resides along with static dir and other files but i am still getting the same error. I also changed this property <Directory "${SRVROOT}/htdocs"> to <Directory "c:/app-tomcat/webapps/ROOT"> but the error persists. No other modifications were done to the httpd.conf or any other file in Apache except for changing the log level and enabling mod_proxy and mod_proxy_http module.

Any idea how i can resolve this?

Technext
  • 147
  • 2
  • 8
  • It always helps if while down-voting you can comment as well so i can improve on it. Not everyone is comfortable working in all areas. – Technext Sep 23 '18 at 14:26

1 Answers1

1

It seems you only redirect /lab, but the static files are not in /lab, they are in /static.

So you should also redirect /static so that these files can be accessed.

Another way would be to just place the static files into the appropriate Apache directory.

Edit

The error message about file not found says

C:/apache24/htdocs/static/css/main.00e8fde0.css

Assuming The DocumentRoot is C:/apache24/htdocs that means the URL to access the file is /static/css/main.00e8fde0.css.

RalfFriedl
  • 3,108
  • 4
  • 13
  • 17
  • I'm not sure whether i have explained it using the right terms but what i want to say is that the website is `company.com` and what i want is if i hit URL A i.e., `http://apps.company.com/lab`, it should take me to URL B. I have not created any dir called `lab` under `${SRVROOT}/htdocs`. All code is present in `c:/app-tomcat/webapps/ROOT` path. Under this path, there is index.html, `static` dir. `static` dir further contains `css` and `js` directories. I want _everything_ to be served from URL B. – Technext Sep 23 '18 at 13:52
  • But your `ProxyPass` says `/lab` and not `/`. So how is `/static` supposed to end up at your URL B? – RalfFriedl Sep 23 '18 at 13:56
  • Apologies for my lack of understanding. I have not used Apache really but given the query i have and the clarification i mentioned in my comment, is there no way i can use `http://apps.company.com/lab` and access URL B without moving any `static` content to Apache's dir? When you said, redirecting `/static`, do i need to add two extra lines for `ProxyPass` and `ProxyPassReverse`? – Technext Sep 23 '18 at 14:09
  • I don't know enough about your setup to answer that. But you may try `/` instead of `/lab`. – RalfFriedl Sep 23 '18 at 14:11
  • I think this is what you meant, correct? Added `ProxyPass /static http://svrdev-73:6020/static nocanon` line and this one, `ProxyPassReverse /static http://svrdev-73:6020/static`. Though i am getting some errors in browser's console section, i can see the page contents. :) – Technext Sep 23 '18 at 14:19
  • Also, in your answer, when you said `but the static files are not in /lab, they are in /static`, did you mean to say that the static files are not lying `directly` in parallel with `index.html` file but instead in a sub-dir named `static`? Is that the reason i had to handle `static` separately? Is there a way `/static` can be clubbed with `/lab` so i can have only one line each for `ProxyPass` and `ProxyPassReverse`? – Technext Sep 23 '18 at 14:22