Reverse Proxying a website path...

Alles, was den Apache betrifft, kann hier besprochen werden.

Reverse Proxying a website path...

Postby verbal_666 » 25. June 2022 11:35

Hello all!!!
A stupid question!!! :roll: :roll: :roll:

I'm hosting an HTTPS website, all working fine with default port 443 and correct signed certificate.

Assuming the host is responding to https://localhost . From root website, i can do everything inside the DocumentRoot path.

NOW I NEED to reverse proxing a path from / to an external web interface.

https://localhost ok to DocumentRoot
https://localhost/app ok to DocumentRoot/app
https://localhost/APPEXT i want to proxy this path to an external product which serves a web interface on 8080

WHAT I DID, with theese results :-(

IF I COMPLETELY REPLACE the original VirtualHost with

Code: Select all
<VirtualHost _default_:443>
ServerName APPEXT
SSLEngine on
SSLCertificateFile "${CERTROOT}\my.pem"
SSLCertificateKeyFile "${CERTROOT}\my.key"
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>


External WebInteface responds fine without problems.
But this is not what i want to do, neither hosting on a new listening port.

I WANT to make this same proxing inside the original hosted VirtualHost.
But, proxying with a

Code: Select all
<VirtualHost _default_:443>
DocumentRoot "[myhome]"
ServerName [myname]
SSLEngine on
SSLCertificateFile "${CERTROOT}\my.pem"
SSLCertificateKeyFile "${CERTROOT}\my.key"

ProxyPreserveHost On
ProxyPass /APPEXT http://localhost:8080/
ProxyPassReverse /APPEXT http://localhost:8080/

</VirtualHost>


Make the proxying to redirect, but all the path by "APPEXT" missed the redirect, and are managed by Apache, so i have a 404.
https://localhost/APPEXT reditects to http://localhost:8080/ but all APPEXT path NOT!
So, if i need http://localhost:8080/style.css and i call https://localhost/APPEXT/style.css i get a 404 from Apache to https://localhost/style.css :cry: :cry: :cry:

Is there a method to get a full reverse proxying?
Do i need a create a new VirtualHost? How?
Thanks.
verbal_666
 
Posts: 5
Joined: 25. June 2022 10:41
XAMPP version: 8.0.13
Operating System: Windows 10

Re: Reverse Proxying a website path...

Postby verbal_666 » 25. June 2022 16:13

No way to make Apache to add a new VirtualHost, serving only the "https://localhost/APPEXT" compatible with the original running and with a simple?

Code: Select all
<VirtualHost _default_:443>
DocumentRoot "[myhome]"
ServerName [myname]
[SSL_STUFFS]
</VirtualHost>

<VirtualHost ??? ??? ??? >
ServerName APPEXT
[SSL_STUFFS]
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>


Thanks!!! :oops: :oops: :oops:
verbal_666
 
Posts: 5
Joined: 25. June 2022 10:41
XAMPP version: 8.0.13
Operating System: Windows 10

Re: Reverse Proxying a website path...

Postby Nobbie » 27. June 2022 07:18

Dont use _default_ VirtualHost in namebased context. Instead simply use *:443 in all VirtualHosts.

P.S.: Due to your first posting, a Proxy does no redirect, you probably have a redirect somewhere in a .htaccess file or so.

P.P.S..: You seem to have a big misunderstanding of VirtualHost. A Virtualhost with ServerName APPEXT does not serve from https://localhost/APPEXT, but from https://APPEXT, thats a huge difference.
Nobbie
 
Posts: 13165
Joined: 09. March 2008 13:04

Re: Reverse Proxying a website path...

Postby verbal_666 » 28. June 2022 22:40

Nobbie wrote:P.S.: Due to your first posting, a Proxy does no redirect, you probably have a redirect somewhere in a .htaccess file or so.

I got no .htaccess.
In reality,

Code: Select all
ProxyPreserveHost On
ProxyPass /APPEXT http://localhost:8080/
ProxyPassReverse /APPEXT http://localhost:8080/


in first conf does the correct redirect to http://localhost:8080, but, as said, all the calls to

https://localhost/APPEXT reditects to http://localhost:8080/


So if i call https://localhost/APPEXT i can connect to http://localhost:8080, but any server object in localhost:8080, obviously, are treated as Apache internal Virtualhost,
https://localhost/APPEXT --> serving correctly external App http://localhost:8080 [layout is bad... follow...] --> serving its /style.css is catched by Apache as https://localhost/style.css [404] and not as https://localhost/APPEXT/style.css [200, loaded!!!]

:cry:

Nobbie wrote:P.P.S..: You seem to have a big misunderstanding of VirtualHost. A Virtualhost with ServerName APPEXT does not serve from https://localhost/APPEXT, but from https://APPEXT, thats a huge difference.

"ServerName APPEXT" was only an example.



I solved my problem binding to a new listening port... i got no other way, with only one ServerName (external) with a single internal ip.

Code: Select all
<VirtualHost *:443>
DocumentRoot "[myhome]"
ServerName [myname]
[SSL_STUFFS]
</VirtualHost>

Listen 444
<VirtualHost *:444>
ServerName [myname]
[SSL_STUFFS]
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>


This (obviously) works!!! :lol:
verbal_666
 
Posts: 5
Joined: 25. June 2022 10:41
XAMPP version: 8.0.13
Operating System: Windows 10

Re: Reverse Proxying a website path...

Postby Nobbie » 29. June 2022 07:28

This works, because you have a Redirect on 443, as i already said. Once more: a ProxyPass does NOT redirect. Again for you: does not redirect. But as you have a redirect, it must be somewhere else. Changing Port 443 to 444 in the VirtualHost means also, that it is not redirected.

The far better solution would be, to find the redirect and remove it. An .htaccess is only one option, it could also be in the Apache Config as well as in the Script code.
Nobbie
 
Posts: 13165
Joined: 09. March 2008 13:04

Re: Reverse Proxying a website path...

Postby verbal_666 » 29. June 2022 08:22

Nobbie wrote:This works, because you have a Redirect on 443, as i already said. Once more: a ProxyPass does NOT redirect.

Again?

Maybe it's time to explain the architecture,
[INTERNET] --> [DOMAIN WITH ITS DNS] --> [ROUTER FORWARDING 443 & 444 TO INTERNAL LAN] --> [LAN] --> [SERVER] --> [APACHE WITH ITS APPS ] + [APP WITH ITS WEBIF]

443 works for Apache Apps.
444 works with external App, using reverse proxying and Apache signed certificate.
So ProxyPass redirect works. It's the normal procedure for reverse proxying, documented by Apache!!! :roll:
If you mean "ROUTER FORWARDING 443 & 444 TO INTERNAL LAN", it was obvious, so never mentioned.

Code: Select all
Again for you: does not redirect. But as you have a redirect, it must be somewhere else. Changing Port 443 to 444 in the VirtualHost means also, that it is not redirected.

Again,
443 works for Apache Apps, on server.
444 works with external App, on same server.

I do not have any other conf than httpd and ssl. It's a clean Apache install, and no .htaccess files at all in any path.

As said, with 443 and 444 i can use all the apps, Apache and the other WebIf (that does not have SSL support, only plain HTTP :cry: ) without problem at all!!! :oops:

The far better solution would be, to find the redirect and remove it. An .htaccess is only one option, it could also be in the Apache Config as well as in the Script code.

Write how... since you continue writing "it does not work", but it works, but never answered the original question :roll:
verbal_666
 
Posts: 5
Joined: 25. June 2022 10:41
XAMPP version: 8.0.13
Operating System: Windows 10

Re: Reverse Proxying a website path...

Postby Nobbie » 29. June 2022 08:50

A fool wth a tool remains a fool.

I didnt say it does not work. Its simply a stupid solution.

Last not least, a ProxyPass is NOT a redirect, it never was and never will be. You simply have no idea, how it works.

444 works with external App


WRONG! 444 also works with Apache, not with external app. Instead 444 requests data from Apache, then Apache requests data from localhost:8080 and finally passes retrieved data back via 444. From outside it looks as if there is only Apache (and actually there is only Apache), but Apache requests the (hidden from outside) localhost:8080. Thats a totally different approach than a redirect.

Finally I give up, its your stuff. Good luck.
Nobbie
 
Posts: 13165
Joined: 09. March 2008 13:04

Re: Reverse Proxying a website path...

Postby verbal_666 » 29. June 2022 09:21

Nobbie wrote:A fool wth a tool remains a fool.

No more to say!!! To someone saying "fool". Idiot.

WRONG! 444 also works with Apache, not with external app. Instead 444 requests data from Apache, then Apache requests data from localhost:8080 and finally passes retrieved data back via 444. From outside it looks as if there is only Apache (and actually there is only Apache), but Apache requests the (hidden from outside) localhost:8080. Thats a totally different approach than a redirect.

THIS IS A REDIRECT, A PROXY-REVERSE REDIRECT. PROXY-REVERSE is a redirect, in term of http flows!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Obviously the trace is,
[INTERNET] --> [DOMAIN WITH ITS DNS] --> [ROUTER FORWARDING 444 TO INTERNAL LAN] --> [LAN] -->
[SERVER] --> [APACHE 444] --> [REVERSE-PROXY which IS A REDIRECT!!!!!!!!!!!!!!!!!!!!!!] <--> [APP AT http://localhost:8080 WITH ITS WEBIF, and now also Apache SSL signed certificate by Apache Environment]

IT'S OBVIOUS THE ENGINE IS APACHE!!!!!!!!!!!!!!!!!!! What i'm asking for otherwise :roll: :roll: :roll: it's to give WebIf without SSL an Apache SSL redirect with full SSL... if you do not understand, yes give up!!!

If i wanted to expose http://localhost:8080 outside, i simply could make a rule [ROUTER FORWARDING 8080 TO INTERNAL LAN] !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! :roll:


Finally I give up, its your stuff. Good luck.

Good luck to you.
verbal_666
 
Posts: 5
Joined: 25. June 2022 10:41
XAMPP version: 8.0.13
Operating System: Windows 10

Re: Reverse Proxying a website path...

Postby GabrielLuke » 11. August 2022 15:38

Check that —mod rewrite— mod proxy is loaded in your config file. Then, in your virtualhost section, include something similar to this.
Code: Select all
ProxyPass /app1 http://app1:8080
ProxyPassReverse /app1 http://app1:8080

ProxyPass /app2 http://app2:8080
ProxyPassReverse /app2 http://app2:8080


ProxyPass /app3 http://app3:8080
ProxyPassReverse /app3 http://app3:8080

I'm making some assumptions here, such as the fact that you're serving http on port 8080 on all three servers.

I'm just curious, why do you want to pass traffic based on the URL? Why not base it on a subdomain, such as app1.company.com, app2.company.com, or app3.company.com? You could easily do this, and it appears to be better practise, depending on your goals.
GabrielLuke
 
Posts: 12
Joined: 02. August 2021 12:20
XAMPP version: 3.2.4
Operating System: Windows 10


Return to Apache

Who is online

Users browsing this forum: No registered users and 233 guests