ANC_G7
ANC_G7

Reputation: 21

relative path js and css not found in 404html nginx static web site

I want to create static web site in nginx. I need a 404.html but it have some js and css link ,path is root, blow

<link href="css/custom.css" rel="stylesheet">
<link href="js/custom.js" rel="stylesheet">

nginx

error_page 404 /404.html;

when i access a not exist file url like http://www.test.com/xxx is ok 404.html correct show.

but when i access url with like http://www.test.com/xxx/xxx, i get a wrong page, open console, i found my css and js path changed http://www.test.com/xxx/custom.css

I see if i change js and css file relative path to absolte path. but i need relative path. I expect get correct 404.html with its js and css file with any url when 404 and js/css use relative.

How to config nginx or other?

Upvotes: 1

Views: 536

Answers (2)

ANC_G7
ANC_G7

Reputation: 21

not to change in nginx

nginx still

error_page 404 /404.html;

change html

css/custom.css

to

/css/custom.css

same to js files

this resolve my problem

Upvotes: 1

BryGom
BryGom

Reputation: 699

Try using a location in nginx configuration

error_page 404 /404.html;
location = /404.html {
           root /usr/share/nginx/html;
           internal;
}

Upvotes: 0

Related Questions