ÔõÑùʹÓÃNginx Proxy ManagerʵÏÖÍøÕ¾»á¼ûÈÕÖ¾µÄÊÕÂÞÓëÆÊÎö
ÔõÑùʹÓÃNginx Proxy ManagerʵÏÖÍøÕ¾»á¼ûÈÕÖ¾µÄÊÕÂÞÓëÆÊÎö
СÐò£º
Ëæ×Å»¥ÁªÍøµÄ¿ìËÙÉú³¤£¬ÍøÕ¾ÈÕÖ¾ÆÊÎöÒѾ³ÉΪÁËÖ÷ÒªµÄÒ»»·¡£Í¨¹ý¶ÔÍøÕ¾»á¼ûÈÕÖ¾µÄÊÕÂÞÓëÆÊÎö£¬¿ÉÒÔÏàʶÓû§µÄÐÐΪϰ¹ß¡¢ÓÅ»¯ÍøÕ¾ÐÔÄÜÒÔ¼°Ë¢ÐÂÓû§ÌåÑé¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃNginx Proxy ManagerÀ´ÊµÏÖÍøÕ¾»á¼ûÈÕÖ¾µÄÊÕÂÞÓëÆÊÎö£¬°üÀ¨ÉèÖÃNginx Proxy Manager¡¢ÍøÂçÍøÕ¾»á¼ûÈÕÖ¾¡¢´æ´¢ºÍÆÊÎöÈÕÖ¾Êý¾ÝµÈÏêϸ°ì·¨¡£Í¬Ê±£¬ÌṩÁËÏà¹ØµÄ´úÂëʾÀýÒÔ¹©²Î¿¼¡£
Ò»¡¢ÉèÖÃNginx Proxy Manager
×°ÖÃNginx Proxy Manager
Ê×ÏÈ£¬ÎÒÃÇÐèҪװÖÃNginx Proxy Manager¡£¿ÉÒÔͨ¹ý¹Ù·½ÍøÕ¾£¨https://nginxproxymanager.com/£©ÏÂÔØ×îа汾µÄNginx Proxy Manager£¬²¢Æ¾Ö¤Îĵµ¾ÙÐÐ×°Öá£
ÉèÖÃNginx
×°ÖÃÍê³Éºó£¬ÐèÒª¾ÙÐÐNginxµÄÉèÖá£ÔÚNginxÉèÖÃÎļþÖУ¬¼ÓÈëÒÔÏÂÉèÖöΣº
server { listen 80; server_name example.com; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; # ÆäËûÊðÀíÏà¹ØÉèÖÃ... } }
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬example.comΪҪÊðÀíµÄÓòÃû£¬http://localhost:8080ΪÏÖʵµÄWebЧÀÍÆ÷µØµã¡£
ÉèÖÃSSLÖ¤Êé
ÈôÊÇÐèÒª¿ªÆôHTTPS»á¼û£¬ÐèÒªÉèÖÃSSLÖ¤Êé¡£¿ÉÒÔͨ¹ýNginx Proxy ManagerµÄWeb½çÃæÀ´Íê³ÉÖ¤ÊéµÄÉèÖúÍÖÎÀí¡£
¶þ¡¢ÍøÂçÍøÕ¾»á¼ûÈÕÖ¾
ÆôÓÃNginx»á¼ûÈÕÖ¾
ÔÚNginxÉèÖÃÎļþÖУ¬Ìí¼ÓÒÔÏÂÉèÖöΣº
http { access_log /var/log/nginx/access.log; # ÆäËûÈÕÖ¾Ïà¹ØÉèÖÃ... }
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬/var/log/nginx/access.logΪÈÕÖ¾ÎļþµÄ·¾¶¡£
ÉèÖÃÈÕÖ¾ÃûÌÃ
ΪÁËÀû±ãÆÊÎöºÍ´æ´¢£¬¿ÉÒÔÉèÖÃ×Ô½ç˵µÄÈÕÖ¾ÃûÌá£ÔÚNginxÉèÖÃÎļþÖУ¬¼ÓÈëÒÔÏÂÉèÖöΣº
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 /var/log/nginx/access.log main; # ÆäËûÈÕÖ¾Ïà¹ØÉèÖÃ... }
µÇ¼ºó¸´ÖÆ
ÖØÆôNginx
Íê³ÉÒÔÉÏÉèÖúó£¬ÖØÐÂÆô¶¯NginxЧÀÍʹÉèÖÃÉúЧ¡£
Èý¡¢´æ´¢ºÍÆÊÎöÈÕÖ¾Êý¾Ý
×°ÖÃELK Stack
ΪÁË´æ´¢ºÍÆÊÎöÈÕÖ¾Êý¾Ý£¬¿ÉÒÔʹÓÃELK Stack£¨Elasticsearch¡¢Logstash¡¢Kibana£©¡£¿ÉÒÔͨ¹ý¹Ù·½ÍøÕ¾£¨https://www.elastic.co/£©ÏÂÔØ×îа汾µÄELK Stack£¬²¢Æ¾Ö¤Îĵµ¾ÙÐÐ×°Öá£
ÉèÖÃLogstash
ÔÚLogstashµÄÉèÖÃÎļþÖУ¬¼ÓÈëÒÔÏÂÉèÖöΣº
input { file { path => "/var/log/nginx/access.log" start_position => "beginning" sincedb_path => "/dev/null" ignore_older => 0 } } filter { # Êý¾Ý¹ýÂËÉèÖÃ... } output { elasticsearch { hosts => ["localhost"] index => "nginx-%{+YYYY.MM.dd}" } }
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬/var/log/nginx/access.logΪNginx»á¼ûÈÕÖ¾ÎļþµÄ·¾¶¡£
ÉèÖÃKibana
ÔÚKibanaµÄÉèÖÃÎļþÖУ¬ÐÞ¸ÄÒÔÏÂÉèÖÃÏ
elasticsearch.hosts: ["http://localhost:9200"]
µÇ¼ºó¸´ÖÆ
ËÄ¡¢ÈÕÖ¾ÆÊÎöÓë¿ÉÊÓ»¯
»á¼ûKibana
ÔÚä¯ÀÀÆ÷Öлá¼ûKibanaµÄµØµã£¨Ä¬ÒÔΪhttp://localhost:5601£©¡£
½¨ÉèË÷Òý
ÔÚKibanaÖУ¬½¨ÉèÒ»¸öÃûΪ”nginx-*”µÄË÷Òý£¬ÒÔ±ã¿ÉÒÔ¶ÔNginxµÄ»á¼ûÈÕÖ¾¾ÙÐÐÅÌÎʺͿÉÊÓ»¯¡£
Ó¦ÓÃÅÌÎÊÓë¿ÉÊÓ»¯
ÔÚKibanaÖУ¬¿ÉÒÔ½¨ÉèÖݪÖÅÌÎʺͿÉÊÓ»¯Í¼±í£¬ÒÔÆÊÎöNginxµÄ»á¼ûÈÕÖ¾¡£ÀýÈ磬¿ÉÒÔ½¨ÉèÒ»¸öÒDZíÅÌ£¬°üÀ¨»á¼ûÁ¿¡¢»á¼ûȪԴ¡¢»á¼ûƵÂʵÈͼ±í¡£
½áÓ
ͨ¹ýʹÓÃNginx Proxy ManagerÀ´ÊµÏÖÍøÕ¾»á¼ûÈÕÖ¾µÄÊÕÂÞÓëÆÊÎö£¬ÎÒÃÇ¿ÉÒÔ¸üºÃµØÃ÷È·Óû§ÐÐΪ¡¢ÓÅ»¯ÍøÕ¾ÐÔÄÜ£¬´Ó¶øÌáÉýÓû§ÌåÑ顣ϣÍû±¾ÎÄÄܹ»¶Ô¶ÁÕßÔÚÏÖʵÏîÄ¿ÖÐÓ¦ÓÃNginx Proxy Manager¾ÙÐÐÍøÕ¾»á¼ûÈÕÖ¾µÄÊÕÂÞÓëÆÊÎöÌṩһЩ²Î¿¼¡£×£ÄãʹÓÃÓä¿ì£¡
ÒÔÉϾÍÊÇÔõÑùʹÓÃNginx Proxy ManagerʵÏÖÍøÕ¾»á¼ûÈÕÖ¾µÄÊÕÂÞÓëÆÊÎöµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡