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

Nginx»á¼ûÈÕÖ¾ÆÊÎöÉèÖã¬ÊµÊ±¼à¿ØÍøÕ¾»á¼ûÇéÐÎ

nginx»á¼ûÈÕÖ¾ÆÊÎöÉèÖã¬ÊµÊ±¼à¿ØÍøÕ¾»á¼ûÇéÐÎ

NginxÊÇÒ»¿î¸ßÐÔÄܵÄWebЧÀÍÆ÷ºÍ·´ÏòÊðÀíЧÀÍÆ÷£¬ÓëÆäËûWebЧÀÍÆ÷Ïà±È£¬ÔÚ´¦Àí¾²Ì¬×ÊÔ´ºÍ¸ß²¢·¢ÇëÇó·½Ãæ¾ßÓнϺõÄÐÔÄÜÓÅÊÆ¡£¹ØÓÚÔËάְԱÀ´Ëµ£¬ÏàʶÍøÕ¾µÄ»á¼ûÇéÐκÜÊÇÖ÷Òª£¬¿ÉÒÔ̫ͨ¹ýÎöNginxµÄ»á¼ûÈÕÖ¾À´»ñÈ¡Óйػá¼ûÐÐΪ¡¢»á¼ûȪԴµÄÏêϸÐÅÏ¢¡£±¾ÎĽ«ÏÈÈÝÔõÑùÉèÖÃNginx»á¼ûÈÕÖ¾ÆÊÎö£¬²¢ÊµÊ±¼à¿ØÍøÕ¾µÄ»á¼ûÇéÐΡ£

Ê×ÏÈ£¬È·±£NginxÒÑ׼ȷװÖò¢ÕýÔÚÔËÐС£Í¨³£ÇéÐÎÏ£¬NginxµÄ»á¼ûÈÕ־λÓÚ/var/log/nginx/access.logÎļþÖС£ÎÒÃÇ¿ÉÒÔͨ¹ýÉèÖÃNginx£¬Ê¹Æ佫ÈÕ־дÈëÖ¸¶¨µÄÎļþ£¬²¢Æ¾Ö¤Ô¤¶¨µÄÃûÌüͼ»á¼ûÐÅÏ¢¡£

ÔÚNginxÉèÖÃÎļþ£¨Í¨³£Îª/etc/nginx/nginx.conf£©ÖÐÕÒµ½http²¿·Ö£¬²¢Ìí¼ÓÒÔÏÂÉèÖãº

http {
    ...
    
    log_format custom_format '$remote_addr - $remote_user [$time_local] '
                          '"$request" $status $body_bytes_sent '
                          '"$http_referer" "$http_user_agent"';
    
    access_log /var/log/nginx/access.log custom_format;
    
    ...
}

µÇ¼ºó¸´ÖÆ

ÉÏÊö´úÂë½ç˵ÁËÒ»¸ö×Ô½ç˵µÄÈÕÖ¾ÃûÌã¨custom_format£©£¬ÆäÖаüÀ¨Á˼ͼ»á¼ûÐÅÏ¢ËùÐèµÄÖÖÖÖ×ֶΡ£ÏêϸÈÕÖ¾ÃûÌõÄÉèÖÿÉÒÔƾ֤ÏÖʵÐèÇó¾ÙÐе÷½â¡£access_logÖ¸ÁîÖ¸¶¨ÁËÈÕÖ¾ÎļþµÄ·¾¶ºÍÃûÌá£ÔÚÕâ¸öÀý×ÓÖУ¬ÎÒÃǽ«ÈÕÖ¾ÎļþÃüÃûΪaccess.log£¬²¢Ê¹ÓÃ×Ô½ç˵µÄÃûÌþÙÐмͼ¡£

¸üÐÂÍê³ÉÉèÖúó£¬ÐèÒªÖØÆôNginxʹÉèÖÃÉúЧ£º

sudo systemctl restart nginx

µÇ¼ºó¸´ÖÆ

ÏÖÔÚ£¬Nginx½«»áƾ֤ÉèÖõÄÃûÌý«»á¼ûÐÅϢдÈë/var/log/nginx/access.logÎļþÖС£½ÓÏÂÀ´£¬ÎÒÃÇ¿ÉÒÔʹÓÃÈÕÖ¾ÆÊÎö¹¤¾ßÀ´ÆÊÎöNginxµÄ»á¼ûÈÕÖ¾£¬ÒÔ±ã¸üºÃµØÏàʶÍøÕ¾µÄ»á¼ûÇéÐΡ£

³£ÓõÄÈÕÖ¾ÆÊÎö¹¤¾ßÓÐELK Stack¡¢Awstats¡¢GoAccessµÈ¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝʹÓÃGoAccessʵʱ¼à¿ØNginx»á¼ûÇéÐΡ£

GoAccessÊÇÒ»¸ö»ùÓÚÏÂÁîÐеÄʵʱÈÕÖ¾ÆÊÎöÆ÷£¬¿ÉÒÔ±¬·¢Ö±¹Û¡¢¿É½»»¥µÄ±¨¸æ£¬²¢½«Ð§¹ûÒÔHTMLÃûÌþÙÐÐչʾ¡£Ê×ÏÈ£¬ÎÒÃÇÐèÒªÉó²éGoAccessÊÇ·ñÒÑ×°Öã¬ÈôδװÖã¬Ôò¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁî¾ÙÐÐ×°Öãº

sudo apt-get install goaccess

µÇ¼ºó¸´ÖÆ

×°ÖÃÍê³Éºó£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´ÊµÊ±¼à¿ØNginxµÄ»á¼ûÇéÐΣº

sudo tail -f /var/log/nginx/access.log | goaccess -a -o /var/www/html/report.html

µÇ¼ºó¸´ÖÆ

ÉÏÊöÏÂÁîÖУ¬tail -fÓÃÓÚ¼àÊÓNginxµÄ»á¼ûÈÕÖ¾Îļþ£¬goaccessÏÂÁʵʱÆÊÎöÈÕÖ¾£¬²¢ÌìÉú±¨¸æ¡£-a±ê¼ÇÓÃÓÚÏÔʾËùÓеĻá¼ûÐÅÏ¢£¬-oÓÃÓÚÖ¸¶¨±¨¸æµÄÊä³ö·¾¶¡£ÔÚÕâ¸öÀý×ÓÖУ¬±¨¸æ½«ÒÔHTMLÃûÌô洢ÔÚ/var/www/html/report.htmlÎļþÖС£

ÏÖÔÚ£¬ÎÒÃÇ¿ÉÒÔͨ¹ýä¯ÀÀÆ÷»á¼ûhttp://your_server_ip/report.htmlÀ´Éó²éʵʱµÄNginx»á¼û±¨¸æ¡£±¨¸æ½«Ìṩ¹ØÓÚ»á¼ûÁ¿¡¢»á¼ûȪԴ¡¢³£¼ûÓû§ÊðÀí¡¢HTTPÏìÓ¦ÂëµÈÐÅÏ¢£¬×ÊÖúÎÒÃǸüºÃµØÏàʶÍøÕ¾µÄ»á¼ûÇéÐκÍÐÔÄÜ״̬¡£

ͨ¹ýÉèÖÃNginx»á¼ûÈÕÖ¾ÆÊÎöºÍʵʱ¼à¿Ø£¬ÎÒÃÇÄܹ»ÊµÊ±»ñÈ¡ÓйØÍøÕ¾»á¼ûµÄÏêϸÐÅÏ¢¡£Õâ¹ØÓÚÏàʶÍøÕ¾ÐÔÄÜ¡¢ÅŲéÒì³£»á¼ûÐÐΪÒÔ¼°×ö³öÏìÓ¦µÄÓÅ»¯µ÷½â¶¼ºÜÊÇÓÐ×ÊÖú¡£Ï£Íû±¾ÎĹØÓÚÏ£ÍûÉîÈëÏàʶNginx»á¼ûÈÕÖ¾ÆÊÎöµÄ¶ÁÕßÃÇÓÐËù×ÊÖú¡£

ÒÔÉϾÍÊÇNginx»á¼ûÈÕÖ¾ÆÊÎöÉèÖã¬ÊµÊ±¼à¿ØÍøÕ¾»á¼ûÇéÐεÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ