Proper handling of request_uri in double nginx reverse proxy? Proper handling of request_uri in double nginx reverse proxy? docker docker

Proper handling of request_uri in double nginx reverse proxy?


The cleanest solution would be to modify your upstreams to provide unique paths for all the resources.

It is generally a much easier task to remove parts of a URL from the upstream (with a unique prefix) than to add extra parts to a non-unique one. This is because you can always catch the longer URL and know exactly what it refers to, subsequently returning a 301 or 302 redirect to a shorter and more concise version.

On the other hand, faced with a short request URL, like /, it would be difficult to know for sure which app it may refer to (unless you look into the $http_referer variable, too, and then conditionally issue the redirect based on where the URL request comes from), or unless you implement some sort of spaghetti rules to detect which individual URLs refer to which applications (if you go this route, the map directive may come in handy).

Additionally, consider that, security-wise and when cookies get involved, it is not the best practice to run multiple independent applications on a single domain — a compromise in one application can easily lead to security violations in all the other ones.


As Rinos said, you need to configurate the $live_site var in configuration.php, as this:

public $live_site = '/joomla/';

I've made a complete example in Github that works well after editing that file, and it uses your configs.


enter image description here


 Becomes:


enter image description here


You could try use sub_filter how it mentioned in this answer.

So in your case your nginx config should looks like this one:

server{  listen 80;  server_name _;  location /joomla/ {    proxy_pass          http://localhost:8081/;    proxy_set_header    Referer           $http_referer;    proxy_set_header    X-Forwarded-Port  $server_port;    proxy_set_header    X-Forwarded-Proto $http_x_forwarded_proto;    proxy_set_header    Host              $host;    proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;    proxy_set_header    X-Forwarded-Host  $host;    sub_filter "http://your_server/" "http://your_server/joomla/";    sub_filter_once off;  }}