Nginx·´ÏòÊðÀíЧÀÍÆ÷µÄʵʱ¼à¿ØºÍ×Ô¶¯»¯ÔËάÊÖÒÕÏê½â
nginx·´ÏòÊðÀíЧÀÍÆ÷µÄʵʱ¼à¿ØºÍ×Ô¶¯»¯ÔËάÊÖÒÕÏê½â
СÐò£º
ÔÚ»¥ÁªÍøÁìÓò£¬Ëæ×ÅÍøÂç¹æÄ£µÄÒ»Ö±À©´óºÍÓªÒµµÄÒ»Ö±ÔöÌí£¬Ð§ÀÍÆ÷µÄ¸ºÔØÎÊÌâ³ÉΪһ¸öؽ´ý½â¾öµÄÌôÕ½¡£Nginx×÷Ϊһ¸ö¸ßÐÔÄÜ¡¢¸ß¿É¿¿ÐԵķ´ÏòÊðÀíЧÀÍÆ÷£¬ÒÔÆ侫²ÊµÄ¹¦Ð§ºÍÎÞаÐÔÓ®µÃÁË¿í´ó¿ª·¢ÕßµÄÇàíù¡£ÎªÁ˸üºÃµØʵÏÖNginxЧÀÍÆ÷µÄÔËάºÍ¼à¿Ø£¬±¾ÎĽ«ÏêϸÏÈÈÝNginx·´ÏòÊðÀíЧÀÍÆ÷µÄʵʱ¼à¿ØºÍ×Ô¶¯»¯ÔËάÊÖÒÕ¡£
Ò»¡¢Nginx·´ÏòÊðÀíЧÀÍÆ÷µÄʵʱ¼à¿Ø
Nginx״̬ģ¿é
NginxÌṩÁËһϵÁеÄ״̬ģ¿é£¬¿ÉÒÔ»ñÈ¡NginxЧÀÍÆ÷µÄÖÖÖÖ״̬ÐÅÏ¢¡£Í¨¹ýÔÚNginxµÄÉèÖÃÎļþÖÐÒýÈëÏìÓ¦µÄÄ£¿é£¬²¢ÉèÖöÔÓ¦µÄ¼à¿ØÒ³Ã棬¿ÉÒÔʵÏÖ¶ÔNginxЧÀÍÆ÷µÄʵʱ¼à¿Ø¡£ÀýÈ磬¿ÉÒÔͨ¹ýÒÔÏÂÉèÖý«Nginx״̬ÐÅϢչʾÔÚwebÒ³ÃæÉÏ£º
location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; }
µÇ¼ºó¸´ÖÆ
µÚÈý·½¼à¿Ø¹¤¾ß
³ýÁËNginx¹Ù·½ÌṩµÄ״̬ģ¿éÍ⣬ÉÐÓÐһЩµÚÈý·½¹¤¾ß¿ÉÒÔ×ÊÖúÎÒÃǸüºÃµØʵÏÖ¶ÔNginxЧÀÍÆ÷µÄ¼à¿Ø¡£ÀýÈ磬ÎÒÃÇ¿ÉÒÔʹÓÃopenresty×é¼þÖеÄngx_http_statusÄ£¿éÀ´ÊµÏÖ¶ÔNginx״̬µÄ¼à¿Ø¡£ÏêϸʹÓÃÒªÁìÇë²Î¿¼¹Ù·½Îĵµ¡£
ÈÕÖ¾ÆÊÎö¹¤¾ß
NginxµÄÈÕÖ¾Îļþ¼Í¼ÁËЧÀÍÆ÷µÄÖݪֲÙ×÷ºÍÇëÇóÐÅÏ¢£¬Í¨¹ý¶ÔNginxµÄÈÕÖ¾¾ÙÐÐÆÊÎö£¬¿ÉÒÔ»ñµÃЧÀÍÆ÷µÄÔËÐÐ״̬ºÍÐÔÄÜÖ¸±ê¡£¿ÉÒÔʹÓÃһЩÈÕÖ¾ÆÊÎö¹¤¾ß£¬ÈçELK Stack£¬À´ÊµÏÖ¶ÔNginxЧÀÍÆ÷µÄʵʱ¼à¿Ø¡£
¶þ¡¢Nginx·´ÏòÊðÀíЧÀÍÆ÷µÄ×Ô¶¯»¯ÔËά
NginxµÄÉèÖÃÖÎÀí
NginxµÄÉèÖÃÎļþͨ³£ÐèÒªÊÖ¶¯Ð޸ģ¬ÎªÁËʵÏÖNginxµÄ×Ô¶¯»¯ÔËά£¬ÎÒÃÇ¿ÉÒÔʹÓÃһЩÉèÖÃÖÎÀí¹¤¾ß£¬ÈçAnsible¡¢PuppetµÈ£¬À´ÖÎÀíNginxµÄÉèÖÃÎļþ¡£Í¨¹ýÔÚÉèÖÃÖÎÀí¹¤¾ßÖнç˵¶ÔNginxÉèÖÃÎļþµÄÐ޸ĹæÔò£¬¿ÉÒÔʵÏÖ¶ÔNginxЧÀÍÆ÷ÉèÖõÄ×Ô¶¯Ð޸ĺͰ²ÅÅ¡£
NginxµÄ×Ô¶¯À©ÈÝ
µ±ÓªÒµÁ¿Ôö´óʱ£¬¿ÉÄÜÐèÒªÔöÌíNginxЧÀÍÆ÷µÄÊýÄ¿À´Ó¦¶Ô¸ß¸ºÔØÇéÐΡ£Í¨¹ýʹÓÃÔÆÅÌËãƽ̨£¬ÈçAWS¡¢AzureµÈ£¬ÎÒÃÇ¿ÉÒÔʵÏÖNginxЧÀÍÆ÷µÄ×Ô¶¯À©ÈÝ¡£ÏêϸʵÏÖÒªÁìÊÇ£¬Æ¾Ö¤¸ºÔØƽºâ¹æÔò£¬ÔÚÔÆƽ̨ÉÏ×Ô¶¯½¨ÉèºÍÏú»ÙNginxЧÀÍÆ÷ʵÀý¡£
¿µ½¡¼ì²éºÍ¹ÊÕÏ×Ô¶¯×ªÒÆ
ΪÁË°ü¹ÜЧÀÍÆ÷µÄ¸ß¿ÉÓÃÐÔ£¬ÎÒÃÇÐèÒª¶ÔNginxЧÀÍÆ÷¾ÙÐпµ½¡¼ì²éºÍ¹ÊÕÏ×Ô¶¯×ªÒÆ¡£¿ÉÒÔʹÓÃһЩ¼à¿Ø¹¤¾ß£¬ÈçZabbix¡¢NagiosµÈ£¬À´ÊµÏÖ¶ÔNginxЧÀÍÆ÷µÄ¿µ½¡¼ì²é¡£µ±NginxЧÀÍÆ÷·ºÆð¹ÊÕÏʱ£¬¼à¿Ø¹¤¾ß¿ÉÒÔ×Ô¶¯½«Á÷Á¿Çл»µ½±¸ÓÃЧÀÍÆ÷£¬ÒÔÈ·±£ÓªÒµµÄÒ»Á¬ÐÔ¡£
´úÂëʾÀý1£ºÕ¹Ê¾NginxµÄ״̬ÐÅÏ¢
location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; }
µÇ¼ºó¸´ÖÆ
´úÂëʾÀý2£ºÊ¹ÓÃAnsible×Ô¶¯ÐÞ¸ÄNginxÉèÖÃÎļþ
- name: Update Nginx config file hosts: all become: yes tasks: - name: Copy Nginx config file copy: src: /path/to/nginx.conf dest: /etc/nginx/nginx.conf owner: root group: root mode: '0644' - name: Reload Nginx service: name: nginx state: reloaded
µÇ¼ºó¸´ÖÆ
½áÂÛ£º
Nginx·´ÏòÊðÀíЧÀÍÆ÷µÄʵʱ¼à¿ØºÍ×Ô¶¯»¯ÔËάÊÖÒÕÊÇ°ü¹ÜЧÀÍÆ÷¸ß¿ÉÓÃÐÔºÍÐÔÄܵÄÖ÷ÒªÊֶΡ£Í¨¹ýʵʱ¼à¿ØNginx״̬£¬ÎÒÃÇ¿ÉÒÔʵʱ·¢Ã÷ЧÀÍÆ÷ÎÊÌâ²¢¾ÙÐд¦Öóͷ££»Í¨¹ý×Ô¶¯»¯ÔËά¹¤¾ß£¬ÎÒÃÇ¿ÉÒÔʵÏÖNginxЧÀÍÆ÷µÄ×Ô¶¯°²ÅÅ¡¢ÉèÖÃÐ޸ĺ͹ÊÕÏתÒÆ£¬´Ó¶øÌá¸ßЧÀÍÆ÷µÄ×Ô¶¯»¯Ë®Æ½ºÍÔËάЧÂÊ¡£
ÒÔÉϾÍÊÇNginx·´ÏòÊðÀíЧÀÍÆ÷µÄʵʱ¼à¿ØºÍ×Ô¶¯»¯ÔËάÊÖÒÕÏê½âµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡