1

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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

Try using a location in nginx configuration

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

1 Comment

thanks,i try it. my root not /usr/share/nginx/html, so i change path to my root path and i restart my nginx ,my js/css in 404html still show Failed to load resource: the server responded with a status of 404 ()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.