Reverse proxy and HTTP request from code

I'm trying to figure out what is the "correct" way to make HTTP requests programmatically from web application code when you don't know if you have or are not running behind a reverse proxy (like HTTPD).

  • The web application runs in the root context "/" on the web server.
  • The proxy works with the context "/ proxy" that this web server proxies

Access to index.html from the browser must be requested via /proxy/index.html. But what if there is some code in the web application (for example myscript.js) that will program the HTTP request (for example, xhr.open ("??? / resource").

And this is where the problem comes in because the code is sending this HTTP request to / resource instead of sending it to / proxy / resource.

In other words, the web application code (which runs in the browser) does not know if there is any proxy or not. Be aware that the application can run behind a proxy, but there can be no proxy at all. I mean 3 solutions:

1) The web application automatically resolves the context (e.g. / proxy) by parsing it from the current window.location.path and sending the xhr according to it

2) Refine the web app to require some additional proxy setting from the user and it adds context if set

3) Configure the proxy in some way to re-send non-proxies as urls to the 1: 1 webserver (e.g. / proxy -> webserver /, / -> webserver /)

Which one is "correct" or are there other options?

+3


source to share


1 answer


The web applications on the backend don't need to know if there is a proxy or not above or before them. They should ideally live in their own context, for example. / application /, and if they need to redirect redirects without using hostnames or URLs in them, just URL Path / application / *

Ideally, you can make simple reverse proxy directives according to your scenario number 3:



ProxyPass /XXX/ http://backend/application/
ProxyPassReverse /XXX/ http://backend/application/

      

0


source







All Articles