×ðÁú¿­Ê±¹ÙÍøµÇ¼

Nginx¹ýʧҳÃæÉèÖã¬ÃÀ»¯ÍøÕ¾¹ÊÕÏÌáÐÑ

nginx¹ýʧҳÃæÉèÖã¬ÃÀ»¯ÍøÕ¾¹ÊÕÏÌáÐÑ

ÔÚÍøÕ¾ÔËÓªÀú³ÌÖУ¬ÄÑÃâ»áÓöµ½Ð§ÀÍÆ÷¹ýʧ»òÕßÆäËû¹ÊÕÏ£¬ÕâЩÎÊÌâ»áµ¼ÖÂÓû§ÎÞ·¨Õý³£»á¼ûÍøÕ¾¡£ÎªÁËÌáÉýÓû§ÌåÑéºÍÍøÕ¾ÐÎÏó£¬ÎÒÃÇ¿ÉÒÔ¶ÔNginx¾ÙÐйýʧҳÃæÉèÖã¬ÃÀ»¯ÍøÕ¾¹ÊÕÏÌáÐÑ¡£±¾ÎĽ«ÏÈÈÝÔõÑùͨ¹ýNginxµÄ¹ýʧҳÃæÉèÖù¦Ð§£¬×Ô½ç˵¹ýʧҳÃ棬²¢Ìṩ´úÂëʾÀý×÷Ϊ²Î¿¼¡£

Ò»¡¢ÐÞ¸ÄNginxÉèÖÃÎļþ

Ê×ÏÈ£¬ÎÒÃÇÐèÒª·­¿ªNginxµÄÉèÖÃÎļþ£¬Ò»Ñùƽ³£Î»ÓÚ/etc/nginx/nginx.conf»òÕß/etc/nginx/conf.d/default.conf¡£ÕÒµ½server¿é£¬Ìí¼ÓÈçÏÂÉèÖãº

server {
    ...
    error_page 403 /error/403.html;
    error_page 404 /error/404.html;
    error_page 500 502 503 504 /error/50x.html;
    ...
}

µÇ¼ºó¸´ÖÆ

ÒÔÉÏÉèÖÃÖУ¬error_pageÖ¸ÁîÓÃÓÚÉèÖùýʧҳÃæµÄ·¾¶£¬¿ÉÒÔÊÇÍâµØÎļþ·¾¶£¬Ò²¿ÉÒÔÊÇÒ»¸öURI¡£403ÌåÏ־ܾø»á¼û¹ýʧ£¬404ÌåÏÖÒ³Ãæ²»±£´æ¹ýʧ£¬500¡¢502¡¢503¡¢504ÌåÏÖЧÀÍÆ÷¹ýʧ¡£

¶þ¡¢½¨Éè¹ýʧҳÃæ

ÎÒÃÇÐèÒª½¨Éè¶ÔÓ¦µÄ¹ýʧҳÃæÎļþ£¬²¢ÉúÑÄÔÚÖ¸¶¨µÄ·¾¶Ï¡£½ÓÏÂÀ´£¬ÎÒÃÇÒÔ403¹ýʧҳÃæΪÀý£¬½¨ÉèÒ»¸öÃûΪ403.htmlµÄÎļþ£¬²¢½«ÆäÉúÑÄÔÚnginxÉèÖÃĿ¼ÏµÄerrorĿ¼ÖС£

$ sudo mkdir /usr/share/nginx/error
$ sudo touch /usr/share/nginx/error/403.html
$ sudo nano /usr/share/nginx/error/403.html

µÇ¼ºó¸´ÖÆ

ÔÚ403.htmlÖУ¬ÎÒÃÇ¿ÉÒÔ×Ô½ç˵¹ýʧÌáÐÑÐÅÏ¢£¬¿ÉÒÔÌí¼ÓһЩÎı¾¡¢Í¼±ê¡¢Á´½ÓµÈÄÚÈÝ£¬ÒÔÌáÐÑÓû§·ºÆðÁË403¹ýʧ¡£

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>403 Forbidden</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f6f6f6;
            margin: 0;
            padding: 50px;
            text-align: center;
        }
        h1 {
            font-size: 24px;
            color: #333;
            margin-bottom: 20px;
        }
        p {
            font-size: 18px;
            color: #666;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <h1>403 Forbidden</h1>
    <p>ǸØÆ£¬ÄúûÓÐȨÏÞ»á¼û¸ÃÒ³Ãæ¡£</p>
</body>
</html>

µÇ¼ºó¸´ÖÆ

Èý¡¢ÖØÆôNginx

Íê³ÉÒÔÉÏÉèÖúó£¬ÎÒÃÇÐèÒªÖØÆôNginxʹÆäÉúЧ¡£

$ sudo systemctl restart nginx

µÇ¼ºó¸´ÖÆ

ËÄ¡¢ÑéÖ¤ÉèÖÃ

ÔÚä¯ÀÀÆ÷ÖÐÊäÈëÒ»¸ö²»±£´æµÄURL£¬ÀýÈçhttp://example.com/123456£¬¼´¿É¿´µ½×Ô½ç˵µÄ404¹ýʧҳÃ档ͬÑùµÄÔ­Àí£¬µ±Óû§Ã»ÓÐȨÏÞ»á¼ûÒ»¸öURLʱ£¬Ò²»áÏÔʾÎÒÃÇ×Ô½ç˵µÄ403¹ýʧҳÃæ¡£

ͨ¹ýNginx¹ýʧҳÃæÉèÖã¬ÎÒÃÇ¿ÉÒÔÃÀ»¯ÍøÕ¾¹ÊÕÏÌáÐÑ£¬ÌáÉýÓû§ÌåÑéºÍÍøÕ¾ÐÎÏó¡£³ýÁË403ºÍ404¹ýʧҳÃæÖ®Í⣬ÎÒÃÇ»¹¿ÉÒÔ×Ô½ç˵ÆäËûÀàÐ͵ĹýʧҳÃ棬Èç500¡¢502¡¢503µÈ¡£Ö»ÐèҪƾ֤ÉÏÊö°ì·¨£¬ÔÚNginxÉèÖÃÎļþÖÐÌí¼Ó¶ÔÓ¦µÄerror_pageÖ¸Á½¨Éè¶ÔÓ¦µÄ¹ýʧҳÃæÎļþ¼´¿É¡£

×ܽ᣺

NginxÌṩÁËÎÞаµÄ¹ýʧҳÃæÉèÖù¦Ð§£¬Ê¹ÎÒÃÇÄܹ»×Ô½ç˵ÍøÕ¾¹ÊÕÏÌáÐÑÒ³Ã档ͨ¹ýÓÅÑŵĹýʧҳÃæÉè¼ÆºÍÌáÐÑÐÅÏ¢£¬ÎÒÃÇ¿ÉÒÔÌá¸ßÓû§ÌåÑ飬ͬʱҲ¿ÉÒÔչʾ¸øÓû§Ò»¸öÓѺúÍרҵµÄÐÎÏó¡£ÒÔÉÏÊǶÔNginx¹ýʧҳÃæÉèÖõÄÏÈÈݺÍʾÀý´úÂ룬ϣÍû¶ÔÄãÔÚÃÀ»¯ÍøÕ¾¹ÊÕÏÌáÐÑ·½ÃæÓÐËù×ÊÖú¡£

ÒÔÉϾÍÊÇNginx¹ýʧҳÃæÉèÖã¬ÃÀ»¯ÍøÕ¾¹ÊÕÏÌáÐѵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ