Nginx»á¼ûÏÞÖÆÉèÖ㬱£»¤Ãô¸ÐÍøÕ¾×ÊÔ´²»±»Ð¹Â¶
nginx»á¼ûÏÞÖÆÉèÖ㬱£»¤Ãô¸ÐÍøÕ¾×ÊÔ´²»±»Ð¹Â¶
Ëæ×ÅÍøÂçµÄÉú³¤£¬Ô½À´Ô½¶àµÄÍøÕ¾±äµÃºÜÊÇÖ÷ÒªºÍÃô¸Ð¡£ÕâЩÍøÕ¾¿ÉÄÜ°üÀ¨Óû§µÄСÎÒ˽ÈËÐÅÏ¢¡¢ÉÌÒµÉñÃØ»òÆäËûÃô¸ÐÊý¾Ý¡£ÎªÁ˱£»¤ÕâЩ×ÊÔ´²»±»Ð¹Â¶»ò±»Î´¾ÊÚȨµÄ»á¼û£¬ÎÒÃÇÐèÒª¶ÔÍøÕ¾¾ÙÐÐÑÏ¿áµÄ»á¼ûÏÞÖÆÉèÖá£ÔÚ±¾ÎÄÖУ¬ÎÒ½«ÏÈÈÝÔõÑùʹÓÃNginxÉèÖÃÀ´ÏÞÖÆ»á¼û£¬±£»¤Ãô¸ÐÍøÕ¾×ÊÔ´¡£
NginxÊÇÒ»¸ö¸ßÐÔÄܵÄWebЧÀÍÆ÷ºÍ·´ÏòÊðÀíЧÀÍÆ÷£¬Í¬Ê±Ò²ÊÇÒ»¸öºÜÊÇÎÞаºÍ¿ÉÀ©Õ¹µÄ¹¤¾ß¡£ËüÌṩÁ˶àÖÖÒªÁìÀ´ÏÞÖÆ»á¼û£¬°üÀ¨»ùÓÚIPµØµãµÄ»á¼û¿ØÖÆ¡¢»ùÓÚHTTPÒªÁìµÄÏÞÖÆ¡¢»ùÓÚÓû§ºÍÃÜÂëµÄÈÏÖ¤µÈ¡£ÏÂÃæÊÇһЩ³£¼ûµÄ»á¼ûÏÞÖÆÉèÖÃʾÀý£º
»ùÓÚIPµØµãµÄ»á¼û¿ØÖÆ
¿ÉÒÔʹÓÃNginxµÄ¡°allow¡±ºÍ¡°deny¡±Ö¸ÁîÀ´ÊµÏÖ»ùÓÚIPµØµãµÄ»á¼û¿ØÖÆ¡£ÀýÈ磬ÏÂÃæµÄÉèÖý«Ö»ÔÊÐíÌض¨IPµØµãµÄÇëÇó»á¼ûÍøÕ¾×ÊÔ´£¬ÆäËûIPµØµãµÄÇëÇ󽫱»¾Ü¾ø£º
location / { deny all; allow 192.168.0.1; }
µÇ¼ºó¸´ÖÆ
ÉÏÊöÉèÖÃÖУ¬¡°deny all¡±ÌåÏÖ¶ÔËùÓÐÇëÇó¾ÙÐоܾø£¬¶ø¡°allow 192.168.0.1¡±ÌåÏÖÖ»ÔÊÐíIPµØµãΪ192.168.0.1µÄÇëÇóͨ¹ý¡£
»ùÓÚHTTPÒªÁìµÄÏÞÖÆ
ÓÐʱ¼ä£¬ÎÒÃÇÏ£ÍûÖ»ÔÊÐíÌض¨µÄHTTPÒªÁ죨ÈçGET¡¢POST£©À´»á¼ûÍøÕ¾×ÊÔ´¡£NginxÌṩÁË¡°limit_except¡±Ö¸ÁîÀ´ÊµÏÖÕâ¸ö¹¦Ð§¡£ÏÂÃæµÄÉèÖÃʾÀý½«Ö»ÔÊÐíGETºÍPOSTÇëÇó»á¼ûÍøÕ¾×ÊÔ´£¬ÆäËûHTTPÒªÁìµÄÇëÇ󽫱»¾Ü¾ø£º
location / { limit_except GET POST { deny all; } }
µÇ¼ºó¸´ÖÆ
ÉÏÊöÉèÖÃÖУ¬¡°limit_except GET POST¡±ÌåÏÖÖ»ÔÊÐíGETºÍPOSTÇëÇóͨ¹ý£¬ÆäËûHTTPÒªÁìµÄÇëÇ󽫱»¾Ü¾ø¡£
»ùÓÚÓû§ºÍÃÜÂëµÄÈÏÖ¤
ÓÐʱ¼ä£¬ÎÒÃÇÏ£ÍûÖ»ÔÊÐí¾ÓÉÉí·ÝÈÏÖ¤µÄÓû§²Å»ª»á¼ûÍøÕ¾×ÊÔ´¡£NginxÌṩÁË»ùÓÚÓû§ºÍÃÜÂëµÄÈÏÖ¤¹¦Ð§¡£ÏÂÃæµÄÉèÖÃʾÀý½«Ö»ÔÊÐí¾ÓÉÓû§ÃûºÍÃÜÂëÈÏÖ¤µÄÓû§»á¼ûÍøÕ¾×ÊÔ´£º
location / { auth_basic "Restricted Access"; auth_basic_user_file /path/to/htpasswd; }
µÇ¼ºó¸´ÖÆ
ÉÏÊöÉèÖÃÖУ¬¡°auth_basic “Restricted Access”¡±ÌåÏÖ¶ÔÇëÇó¾ÙÐÐÉí·ÝÈÏÖ¤£¬²¢ÏÔʾ¡°Restricted Access¡±µÄÌáÐÑÐÅÏ¢¡£¶ø¡°auth_basic_user_file /path/to/htpasswd¡±ÌåÏÖÖ¸¶¨Óû§ÃûºÍÃÜÂëµÄ´æ´¢Îļþ·¾¶¡£
ͨ¹ýÒÔÉÏʾÀý£¬ÎÒÃÇ¿ÉÒÔƾ֤ÐèÒªÎÞаµØÉèÖÃNginxµÄ»á¼ûÏÞÖÆ£¬±£»¤Ãô¸ÐÍøÕ¾×ÊÔ´²»±»Ð¹Â¶¡£ËäÈ»£¬³ýÁËÉÏÊöÒªÁìÍ⣬Nginx»¹ÌṩÁËÆäËûÐí¶àÇ¿Ê¢µÄ»á¼ûÏÞÖÆÉèÖÃÑ¡Ï¿ÉÒÔƾ֤ÏêϸÐèÇó¾ÙÐÐÑ¡ÔñºÍ×éºÏʹÓá£
×ܽáÆðÀ´£¬±£»¤Ãô¸ÐÍøÕ¾×ÊÔ´²»±»Ð¹Â¶ÊÇÿ¸öÍøÕ¾ÖÎÀíÔ±µÄÔðÈΡ£Í¨¹ýºÏÀíÉèÖÃNginxµÄ»á¼ûÏÞÖÆ£¬ÎÒÃÇ¿ÉÒÔÌṩÌØÁíÍâ±£»¤²ã£¬ÔöÇ¿ÍøÕ¾µÄÇå¾²ÐÔ¡£ÔÚÉèÖÃÉèÖÃʱ£¬ÇëÎñ±Ø˼Á¿µ½ÏÖʵÐèÇóºÍÇå¾²ÐÔ£¬×èÖ¹Îó²Ù×÷»òÉèÖùýʧµ¼Ö»á¼ûÕÏ°»òй¶Ãô¸Ð×ÊÔ´¡£Ï£Íû±¾ÎÄÄܹ»Îª¶ÁÕßÌṩÓÐÓõIJο¼ºÍÖ¸µ¼£¬×ÊÖúËûÃǸüºÃµØ±£»¤ÍøÕ¾×ÊÔ´¡£
ÒÔÉϾÍÊÇNginx»á¼ûÏÞÖÆÉèÖ㬱£»¤Ãô¸ÐÍøÕ¾×ÊÔ´²»±»Ð¹Â¶µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡