Страничка 404 «Не найдено» для NGNIX

На днях пришлось изменить спартанский вид странички 404 «Not found» сервера nginx на более человеческий.
Для этого открываем файл старнички в любимом редакторе

vi /usr/local/nginx/html/404.html

и ставим туда желаемое содержание, например:

<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Error 404 Not Found</title>
<style>
<!--
	body {font-family: arial,sans-serif}
	img { border:none; }
//-->
</style>
</head>
<body>
<blockquote>
	<h2>Error 404 Not Found</h2>
	<p>Our apologies for the temporary inconvenience. The requested URL was not found on this server.  We suggest you try one of the links below:
	<ul>
		  <li><b>Verify url and typos</b> - The web page you were attempting to view may not exist or may have moved - try <em>checking the web address for typos</em>.<//li>
		  <li><b>E-mail us</b> - If you followed a link from somewhere, please let us know at <a href="mailto:webmaster@example.com">webmaster@example.com</a>. Tell us where you came from and what you were looking for, and we'll do our best to fix it.</li>
	</ul>
</blockquote>
</body>
</html>

Открываем конфигурационный файл nginx

vi /usr/local/nginx/conf/nginx.conf

и убеждаемся, что там есть такие строки:

error_page 404 /404.html;
location  /404.html {
  internal;
}

то же самое для странички 403

error_page 403 /403.html;
       location = /403.html {
           root   html;
           allow all;
       }

После этого перезапускаем nginx

/usr/local/nginx/sbin/nginx -t && /usr/local/nginx/sbin/nginx -s reload

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *