0

I'm trying to make custom 404 page.

Here is my 404.html:

<html>
<head>
    <meta charset="UTF-8">
    <title>Not Found</title>
</head>
<body>
    <div style="...">
      <div style="...">404</div>
      <div style="...">Page not found</div>
      <img src="404.gif" alt="not found" />
    </div>
</body>
</html>

it works (almost), but I always get "Not found" error trying to load 404.gif

Here is my nginx config (want to make only localhost/main/data and localhost/main/test paths available):

http {
  server {
    listen 80;
    server_name localhost;
    error_page 404 /404.html;

    location = /404.html {
      root /var/www/error/;
    }

    location /404.gif {
      root /var/www/error/;
    }

    location ~ ^/main/(data|test)$ {
    }

When I'm trying to reach any page like http://localhost/main/error_page server returns custom 404 page without gif and error GET http://localhost/main/404.gif 404 (Not Found).

How to load my gif, what path I need to provide in html or how to change config?

Ican
  • 119
  • 2
  • 2
  • 10
  • check error in `/var/log/nginx/errors.log`, it will tell you where its trying to fetch image from, start debugging from there – Dusan Gligoric Dec 09 '20 at 08:45

2 Answers2

0

use the correct image path in image tag src

<img src="../somefolder/somefoler/404.gif" alt="not found" />
Abu Saud
  • 41
  • 6
0

need to redirect any request of this gif like this

location ~* /(.*)404.gif$ {
    try_files $uri $uri/ /404.gif;
}
Ican
  • 119
  • 2
  • 2
  • 10