Strategies for working with a URI when creating an application that is behind a reverse proxy

I am creating an application with a standalone HTTP server that can be directly accessed or put in a reverse proxy (e.g. Apache mod_proxy).

So, let's say my application runs on port 8080, and you configured your Apache as follows:

ProxyPass /myapp http://localhost:8080
ProxyPassReverse /myapp http://localhost:8080

This will cause HTTP requests coming to the main Apache server to go to /myapp/*proxy my application. If the request comes as GET /myapp/bar, my application will see GET /bar. This is as it should be.

There is a problem when creating URIs that need to be translated from my application URI to work correctly through a proxy server (i.e. prepending /myapp/).

The directive ProxyPassReversewill take care of handling this for URIs in HTTP headers (redirects, etc.). But this does not handle URIs in the HTML generated by my application or in static files and templates.

I know filters like mod_proxy_html, but this is a non-standard Apache module, and in any case, such filters may not be available for other front-end web servers that can act as a reverse proxy.

So, I came up with several possible strategies:

  • Require the environment variable to be set somewhere containing the proxy path and add it to all generated URIs. It seems inelegant; it breaks the encapsulation provided by the reverse proxy.

  • Put the proxy path in the configuration file for my application. The same objections as above.

  • URI . ; , , ../ 'es. . , URI, RSS- .

  • Javascript Mungle URI . .

  • URI- , "" , Javascript, CSS .., . , .

. ? ?

+3
1

, . , -, . , , .

, , -, mod_proxy_html, (, URL- -javascript ), . , - , , . ; URL- , HTML .

, :

-, , URL- . URL-. , " .. /'es" , , , () . config-file/environment-variable, , (, -), . , , , . , .

URL- . , /:

(, PHP, RoR ..) , URL- ( , !). - - MVC (, RoR, Django ..), , URL- MVC- , . , , , URL- . , , , URL- , URL- URL-. (, "/, '/, "http://, 'http://) ( , , , ).

, , URL- (, , , ), URL- "". .

Javascript , . URL- , URL- . javascript, , , JS.

CSS URL- CSS CSS ( HTML-), URL-, , . CSS , CSS ... /, . - URL- CSS, , .

, , oddball (, HTML ). , , CSS - URL-. ( ) , -, URL- URL-. , , URL-, - , .

, , URL-, , mod_proxy_html. - , .

, , № 4 (javascript-link-fixup). - javascript ( ), javascript , . .

+6

Source: https://habr.com/ru/post/1725976/


All Articles