'How to Change Web Application Base URL via Nginx

I have the following basic Nginx location configured:

location /truenas/ {
  proxy_pass https://192.168.1.111:8443/;
}

However, the web app that I'm trying to proxy isn't aware that the URL path now starts with /truenas/ and keeps looking for various files as if /truenas/ was not in the path resulting in 404 errors. For example, if I access the web app via https://192.168.1.111/truenas and look at the browser's developer tools network tab I see a GET request for https://192.168.1.111/ui/assets/scripts/product.js. In order for this to work though the application should instead make a request to https://192.168.1.111/truenas/ui/assets/scripts/product.js (notice the /truenas/ start to the path). Is it possible to configure Nginx to somehow tell the application that the URL path now starts with /truenas/ and it should modify its requests accordingly?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source