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

ÔõÑùʵÏÖNginxµÄÈÕÖ¾¼Í¼ÉèÖÃ

ÔõÑùʵÏÖNginxµÄÈÕÖ¾¼Í¼ÉèÖÃ

NginxÊÇÒ»¸ö¸ßÐÔÄܵÄWebЧÀÍÆ÷ºÍ·´ÏòÊðÀíЧÀÍÆ÷ £¬¾­³£±»ÓÃÓڴ´óÐÍÍøÕ¾ºÍÓ¦ÓÃЧÀÍ¡£ÔÚ¿ª·¢ºÍʹÓÃNginxʱ £¬ÈÕÖ¾¼Í¼ÊǺÜÊÇÖ÷ÒªµÄ £¬Ëü¿ÉÒÔÓÃÓÚ¼à¿ØÍøÕ¾Á÷Á¿¡¢ÅÅÅÌÎÊÌâºÍÆÊÎöÓû§ÐÐΪ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÉèÖÃNginxµÄÈÕÖ¾¼Í¼ £¬²¢¸ø³öһЩÏêϸµÄ´úÂëʾÀý¡£

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ÈÕÖ¾µÄÊä³ö·¾¶ºÍÃûÌÃ
    access_log /var/log/nginx/access.log main;

    server {
        # ÏêϸµÄЧÀÍÆ÷ÉèÖÃ
        listen 80;
        server_name example.com;

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}

µÇ¼ºó¸´ÖÆ

ÉÏÊöʾÀýÖÐ £¬log_formatÖ¸Áî½ç˵ÁËÈÕÖ¾¼Í¼µÄÃûÌà £¬mainÊÇÒ»¸ö×Ô½ç˵µÄÃûÌÃÃû³Æ £¬¿ÉÒÔƾ֤ÐèÇó×ÔÐнç˵¡£log_formatÖ¸ÁîÖаüÀ¨ÁËһЩ±äÁ¿ £¬Èç$remote_addrÌåÏÖ¿Í»§¶ËµÄIPµØµã £¬$remote_userÌåÏÖ¿Í»§¶ËµÄÓû§Ãû £¬$time_localÌåÏÖÇëÇóµÄʱ¼ä £¬ $requestÌåÏÖÓû§ÌᳫµÄÇëÇó £¬$statusÌåÏÖЧÀÍÆ÷µÄÏìӦ״̬Âë £¬$body_bytes_sentÌåÏÖЧÀÍÆ÷·¢Ë͵ÄÏìÓ¦Êý¾Ý×Ö½ÚÊý £¬$http_refererÌåÏÖÇëÇóµÄȪԴҳÃæ £¬$http_user_agentÌåÏÖÓû§µÄä¯ÀÀÆ÷ÊðÀíÐÅÏ¢ £¬$http_x_forwarded_forÌåÏÖÇëÇóµÄÕæʵ¿Í»§¶ËIPµØµã£¨ÈôÊÇʹÓÃÁËÊðÀíµÄ»°£©¡£Óû§¿ÉÒÔƾ֤ÐèÒª¾ÙÐÐ×Ô½ç˵ÃûÌá£

access_logÖ¸ÁîÓÃÓÚÉèÖÃNginxµÄaccessÈÕÖ¾µÄÊä³ö·¾¶ºÍÃûÌà £¬ÉÏÊöʾÀýÖеÄ·¾¶Îª/var/log/nginx/access.log £¬ÃûÌÃΪmain¡£Óû§¿ÉÒÔƾ֤ÏêϸÐèÇó¸ü¸Ä·¾¶ºÍÃûÌá£

ΪÁ˲âÊÔÉèÖÃÊÇ·ñÉúЧ £¬¿ÉÒÔʹÓÃÏÂÁînginx -t¾ÙÐмì²é¡£ÈôÊÇÉèÖÃÎļþûÓйýʧ £¬ÏÂÁî»á·µ»Ønginx: configuration file /etc/nginx/nginx.conf test is successful¡£

ÁíÍâ £¬Nginx»¹Ö§³Ö¹ýʧÈÕÖ¾µÄ¼Í¼¡£¹ýʧÈÕÖ¾¿ÉÒÔÓÃÓڼͼһЩЧÀÍÆ÷¶ËµÄ¹ýʧÐÅÏ¢ £¬ÈçÅþÁ¬³¬Ê±¡¢ÇëÇóÎÞЧµÈ¡£ÏÂÃæÊÇÒ»¸ö¹ýʧÈÕÖ¾µÄʾÀý£º

http {
    # È«¾ÖÉèÖÃ
    error_log /var/log/nginx/error.log;

    server {
        # ÏêϸµÄЧÀÍÆ÷ÉèÖÃ
        listen 80;
        server_name example.com;

        location / {
            root /var/www/html;
            index index.html;
        }
    }
}

µÇ¼ºó¸´ÖÆ

ÉÏÊöʾÀýÖÐ £¬error_logÖ¸ÁîÉèÖÃÁ˹ýʧÈÕÖ¾µÄÊä³ö·¾¶ £¬Â·¾¶Îª/var/log/nginx/error.log¡£Í¬Ñù £¬Óû§¿ÉÒÔƾ֤ÏêϸÐèÇó¸ü¸Ä·¾¶¡£

ͨ¹ýÉÏÊöµÄÉèÖà £¬ÎÒÃÇ¿ÉÒÔʵÏÖNginxµÄÈÕÖ¾¼Í¼¹¦Ð§¡£ÔÚÏÖʵʹÓÃÖÐ £¬¿ÉÒÔÍŽáÈÕÖ¾ÆÊÎö¹¤¾ßʹÓà £¬ÈçELK Stack¡¢SplunkµÈ £¬ÒÔ±ã¸üºÃµØÆÊÎöºÍ¼à¿ØÍøÕ¾Á÷Á¿ºÍÓû§ÐÐΪ¡£

×ܽáÆðÀ´ £¬ÉèÖÃNginxµÄÈÕÖ¾¼Í¼ÓÐÒÔϼ¸¸ö°ì·¨£º

ÔÚnginx.confÖнç˵ÈÕÖ¾¼Í¼µÄÃûÌà £¬Ê¹ÓÃlog_formatÖ¸Áî £¬¿ÉÒÔ×Ô½ç˵ÃûÌá£

ʹÓÃaccess_logÖ¸ÁîÉèÖÃaccessÈÕÖ¾µÄÊä³ö·¾¶ºÍÃûÌá£

ʹÓÃerror_logÖ¸ÁîÉèÖùýʧÈÕÖ¾µÄÊä³ö·¾¶¡£

ÒÔÉϾÍÊǹØÓÚÔõÑùʵÏÖNginxµÄÈÕÖ¾¼Í¼ÉèÖõÄÏÈÈÝ £¬Ï£Íû¶Ô¸÷ÈËÓÐËù×ÊÖú¡£

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

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

QR code
ÍøÕ¾µØͼ