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

nginxÔõôÉèÖÃÈÕÖ¾

ÔÚ nginx ÖÐÉèÖÃÈÕÖ¾£¬ÖÁ¹ØÖ÷ÒªµÄÊÇΪÁ˸ú×ÙЧÀÍÆ÷ÐÔÄÜ¡¢Ê¶±ðÎÊÌâºÍ¾ÙÐйÊÕÏɨ³ý¡£ÒÔÏÂÊÇ°ì·¨£ºÔÚ nginx.conf ÖУ¬ÉèÖÃÈÕÖ¾ÃûÌúÍ·¾¶¡£ÉèÖÃÈÕÖ¾ÃûÌã¬ÀýÈç³£ÓÃµÄ main ÃûÌá£Ö¸¶¨»á¼ûºÍ¹ýʧÈÕÖ¾µÄ·¾¶¡£ÉèÖÃÈÕÖ¾¼¶±ð£¬Èç info ÒԼͼËùÓÐÐÂÎÅ¡£ÖØÐÂÆô¶¯ nginx ÒÔʹ¸ü¸ÄÉúЧ¡£ÑéÖ¤ access.log ºÍ error.log ÎļþÖÐÊÇ·ñÓÐÈÕÖ¾ÄÚÈÝ¡£

ÔõÑùÔÚ Nginx ÖÐÉèÖÃÈÕÖ¾

ÔÚ Nginx ÖÐÉèÖÃÈÕÖ¾ÖÁ¹ØÖ÷Òª£¬ÓÉÓÚËüÔÊÐíÄú¸ú×ÙЧÀÍÆ÷ÐÔÄÜ¡¢Ê¶±ðÎÊÌâ²¢¾ÙÐйÊÕÏɨ³ý¡£±¾ÎĽ«Ö¸µ¼ÄúÍê³ÉΪ Nginx ÉèÖÃÈÕÖ¾µÄ°ì·¨¡£

1. ÉèÖÃ Nginx.conf

Ê×ÏÈ£¬ÔÚ Nginx ÉèÖÃÎļþ /etc/nginx/nginx.conf »ò /usr/local/etc/nginx/nginx.conf ÖÐÕÒµ½ÒÔϲ¿·Ö£º

http {
    # ÆäËûÉèÖÃ...

    # ÈÕÖ¾ÉèÖò¿·Ö
    log_format    main  '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';

    # ÉèÖÃÈÕ־·¾¶
    access_log  /path/to/access.log  main;
    error_log  /path/to/error.log  info;

    # ÆäËûÉèÖÃ...
}

µÇ¼ºó¸´ÖÆ

2. ÉèÖÃÈÕÖ¾ÃûÌÃ

ÔÚ log_format Ö¸ÁîÖУ¬Äú¿ÉÒÔÖ¸¶¨ÈÕÖ¾ÌõÄ¿µÄÃûÌá£main ÃûÌÃÊÇÒ»¸ö³£ÓõÄÃûÌã¬Æä°üÀ¨ÒÔÏÂ×ֶΣº

$remote_addr – ¿Í»§¶Ë IP µØµã

$remote_user – ¿Í»§¶ËÓû§±êʶ£¨ÈôÊÇͨ¹ýÉí·ÝÑéÖ¤£©

$time_local – ÍâµØʱ¼ä

$request – ÇëÇóÐÐ

$status – HTTP ״̬Âë

$body_bytes_sent – ·¢Ë͵ÄÏìÓ¦Ìå¾Þϸ

$http_referer – ÒýÓÃȪԴ URL

$http_user_agent – ¿Í»§¶ËÓû§ÊðÀí

$http_x_forwarded_for – ÈôÊÇʹÓÃÊðÀí£¬ÔòΪ¿Í»§¶Ë IP µØµã

3. ÉèÖÃÈÕ־·¾¶

ʹÓà access_log ºÍ error_log Ö¸ÁîÖ¸¶¨»á¼ûºÍ¹ýʧÈÕÖ¾µÄ·¾¶¡£

access_log£º»á¼ûÈÕÖ¾¼Í¼ËùÓпͻ§¶ËÇëÇó¡£

error_log£º¹ýʧÈÕÖ¾¼Í¼ Nginx Óöµ½µÄ¹ýʧºÍÖÒÑÔ¡£

4. ÉèÖÃÈÕÖ¾¼¶±ð

info ¼¶±ð¼Í¼ËùÓÐÐÂÎÅ£¬°üÀ¨¹ýʧ¡¢ÖÒÑÔºÍÐÅÏ¢¡£Äú¿ÉÒÔƾ֤ÐèÒªµ÷½â´Ë¼¶±ð£¬ÀýÈ磺

debug£º¼Í¼µ÷ÊÔÐÅÏ¢£¨×îÏêϸµÄ¼¶±ð£©

notice£º¼Í¼Ö÷ÒªÐÅÏ¢

error£º½ö¼Í¼¹ýʧÐÅÏ¢

5. ÖØÐÂÆô¶¯ Nginx

Íê³ÉÉèÖúó£¬ÖØÐÂÆô¶¯ Nginx ÒÔʹ¸ü¸ÄÉúЧ£º

Systemd£ºsystemctl restart nginx

Upstart£ºservice nginx restart

6. ÑéÖ¤ÈÕÖ¾Îļþ

ÖØÐÂÆô¶¯ Nginx ºó£¬ÄúÓ¦¸ÃÄܹ»ÔÚÖ¸¶¨µÄ·¾¶Öп´µ½ access.log ºÍ error.log Îļþ¡£Äú¿ÉÒÔʹÓÃÎı¾±à¼­Æ÷»òÈÕÖ¾ÆÊÎö¹¤¾ßÉó²éÈÕÖ¾ÄÚÈÝ¡£

ÒÔÉϾÍÊÇnginxÔõôÉèÖÃÈÕÖ¾µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ