meta data for this page
  •  

revproxy

app behind path

Search tags:

  • proxy_pass subfolder
  • path based routing

When hosted app requests assets from absolute URI like: /app.png, all requests are directed to root / location.

Analysis of sent headers shows that there is only one header preserving original subfolder: Referer:.

NginX: Serve application under sub path

    location /mqttx {
        return 302 /mqttx/;
    }

    location /mqttx/ {
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;

        proxy_pass             http://mqttx-web/;
    }

    # mqttx-web loads assets:
    # - /app.js
    # - /app.png
    # - /favicon.ico
    # from absolute paths!
    # so it is impossible to host it under /mqttx/ without this trick:
    if ($http_referer ~ ^https://mqtt.grinndev.ovh/mqttx/) {
       rewrite ^ /mqttx$uri;
    }