Nginx, how to reference files relatively to document location and not to uri

Viewed 24

I have the following NGINX setup:

   include /etc/nginx/mime.types;


   server 
       root /build/build/;

       location ~ (?<no_slash>.+)/$ {
               return 301 $scheme://$host:8080$no_slash;
       }
       location / {
            try_files $uri $uri.html $uri/ index.html =404;
       }
   }

When I enter URL of type https://localhost:8080/foo/bar, and bar file does not exist, I get the index.html file as expected, however as it references some other files in root folder relatively like ./baz.js NGINX searches for the file in build/build/foo/baz.js but cannot find them, giving 404.

Is there a way to make NGINX search for files relatively to index.html location instead of relatively to URI?

0 Answers
Related