0

I have developed nginx config file order to cater some custom error pages. I have created two location blocks to capture the main index.html file and other location to capture the css/js and the images. I have created the cs and the js files seperately and called into the main index file due to the ease of use. But this work only for the following types of url

But if the url cahnges to

https://exmaple.com/abcd/efgd/ or more the css and js won't be in the response.

The css/js and images are in a directory named techops-page-resources. So after checking bit on the issue I found that on the first two url it'll get https://exmaple.com/resources as expected when the given domain is not available. But on the other occasions it'll transformed into https://example.com/abcd/resources/ and this uri doesn't exist. So I've tried different regex patterns and none of them seem to work. The following are the location blocks that I have implemented to set the error pages up.

error_page 503 /pages/maintenance.html;
error_page 502 /pages/50x.html;
error_page 404 /pages/40x.html;

location /pages/ {
   root /var/www/html/ErrorPages/;
}

location /techops-page-resources {
     alias /var/www/html/ErrorPages/pages/techops-page-resources/;
}

}

What I expecting is whenever the 404 error returns I want the main index file to call the techops-page-resources and include them in the the final customized 404 error page as expected. But currently what I only receive is the basic index.html file which is in the pages directory. Is there a correct regex pattern to match only the techops-page-resource as a postfix match as follows

location **some_regex_pattern**/techops-page-resources {
     alias /var/www/html/ErrorPages/pages/techops-page-resources/;
}

I would love to do this in this same architecture without using inline css or js

CK LZEM7
  • 31
  • 6
  • You are probably missing the leading `/` in the URI for the JS/CSS resources in your `.html` file. – Richard Smith Jan 15 '19 at 15:06
  • Thanks @RichardSmith. It worked for me.. I'm a beginner to the nginx sedrver and its workings. So if you can explain how it worked that would be great for my project.. – CK LZEM7 Jan 16 '19 at 06:30
  • A path relative URI is relative to the last `/` in the current document's URI. By adding a leading `/`, you make the path relative to the document root. Some applications need relative paths, and some need absolute paths - there is not one correct solution for all applications. See [this question for more](https://stackoverflow.com/questions/15581445/are-protocol-relative-urls-relative-urls). – Richard Smith Jan 16 '19 at 09:49

0 Answers0