NginxÇå¾²·À»ðǽÉèÖ㬱£»¤ÍøÕ¾²»ÊܶñÒâ¹¥»÷
nginxÇå¾²·À»ðǽÉèÖ㬱£»¤ÍøÕ¾²»ÊܶñÒâ¹¥»÷
СÐò£º
ÔÚµ±½ñ»¥ÁªÍøʱ´ú£¬ÍøÕ¾ÃæÁÙ×ÅÖÖÖÖÇå¾²Íþв£¬Èç¶ñÒâ¹¥»÷¡¢ÈëÇֵȡ£ÎªÁ˱£»¤ÍøÕ¾µÄÊý¾ÝºÍÓû§Òþ˽£¬ÎÒÃÇÐèÒª½ÓÄÉһϵÁв½·¥À´ÔöÇ¿ÍøÕ¾µÄÇå¾²ÐÔ¡£NginxÊÇÒ»¸ö¸ßÐÔÄܵÄWebЧÀÍÆ÷£¬ÔÚÇå¾²·½ÃæÒ²ÌṩÁ˸»ºñµÄ¹¦Ð§£¬ÎÒÃÇ¿ÉÒÔͨ¹ýNginxµÄ·À»ðǽÉèÖÃÀ´±£»¤ÍøÕ¾ÃâÊܶñÒâ¹¥»÷¡£
Ò»¡¢NginxÇå¾²·À»ðǽÉèÖÃ
×°ÖÃNginx
Ê×ÏÈ£¬ÎÒÃÇÐèҪװÖÃNginxЧÀÍÆ÷¡£¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÀ´×°ÖÃNginx£º
$ sudo apt update $ sudo apt install nginx
µÇ¼ºó¸´ÖÆ
ÉèÖÃNginx·À»ðǽ
NginxµÄ·À»ðǽ¹¦Ð§Í¨¹ýÉèÖÃÎļþnginx.confÀ´ÊµÏÖ¡£·¿ªnginx.confÎļþ£¬ÕÒµ½http²¿·ÖµÄÉèÖöΣ¬Ìí¼ÓÒÔÏÂÄÚÈÝ£º
http { # ÔÊÐíµÄIPÁбí deny 192.168.0.1; allow 192.168.0.0/24; # ±ÜÃâĿ¼±éÀú¹¥»÷ location ~ /. { deny all; } # ±ÜÃâSQL×¢Èë¹¥»÷ location ~ inj/ { deny all; } # ÏÞÖÆHTTPÇëÇóÒªÁì if ($request_method !~ ^(GET|HEAD|POST)$) { return 444; } # եȡĿ¼Ë÷ÒýµÄ»á¼û location ~ ^/(.|php) { deny all; } }
µÇ¼ºó¸´ÖÆ
ÒÔÉÏÉèÖÃʾÀýÖУ¬denyÓÃÓھܾøÌض¨µÄIPµØµã£¬allowÓÃÓÚÔÊÐíÌض¨µÄIPµØµã¶Î¡£Í¨¹ýÕâÑùµÄÉèÖã¬ÎÒÃÇ¿ÉÒÔÏÞÖÆÖ»ÓÐÌض¨µÄIPµØµãÄܹ»»á¼ûÎÒÃǵÄÍøÕ¾¡£
location ~ /. { deny all; } Õâ¶ÎÉèÖÃÓÃÓÚ±ÜÃâĿ¼±éÀú¹¥»÷£¬µ±»á¼ûURL°üÀ¨”../”ʱ£¬·µ»Ø403 Forbidden¡£
location ~ inj/ { deny all; } Õâ¶ÎÉèÖÃÓÃÓÚ±ÜÃâSQL×¢Èë¹¥»÷£¬µ±URL°üÀ¨”inj/”ʱ£¬·µ»Ø403 Forbidden¡£
if ($request_method !~ ^(GET|HEAD|POST)$) { return 444; } Õâ¶ÎÉèÖÃÓÃÓÚÏÞÖÆHTTPÇëÇóÒªÁ죬ֻÔÊÐíGET¡¢HEAD¡¢POSTÈýÖÖÒªÁ죬ÆäËûÒªÁì·µ»Ø444ÌåÏÖÎÞÏìÓ¦¡£
location ~ ^/(.|php) { deny all; } Õâ¶ÎÉèÖÃÓÃÓÚեȡ¶ÔĿ¼Ë÷ÒýµÄ»á¼û£¬µ±URLÒÔ”/.”»ò”.php”×îºóʱ£¬·µ»Ø403 Forbidden¡£
ÖØÆôNginxЧÀÍÆ÷
Íê³ÉÒÔÉÏÉèÖúó£¬ÎÒÃÇÐèÒªÖØÆôNginxЧÀÍÆ÷ʹÉèÖÃÉúЧ£º
$ sudo systemctl restart nginx
µÇ¼ºó¸´ÖÆ
¶þ¡¢×ܽá
ͨ¹ýNginxµÄ·À»ðǽÉèÖã¬ÎÒÃÇ¿ÉÒÔÓÐÓõر£»¤ÎÒÃǵÄÍøÕ¾²»ÊܶñÒâ¹¥»÷¡£ÕâЩÉèÖÃÖ»ÊÇÈëÃż¶±ðµÄ·À»¤²½·¥£¬¹ØÓÚ¸üÖØ´óµÄ¹¥»÷£¬ÎÒÃÇÐèÒª½øÒ»²½ÔöÇ¿ÍøÕ¾µÄÇå¾²ÐÔ£¬ÈçʹÓÃWebÓ¦ÓóÌÐò·À»ðǽ£¨WAF£©¡¢HTTPSµÈ¡£ÔÚ½¨ÉèÇå¾²ÍøÕ¾µÄÀú³ÌÖУ¬ÎÒÃÇÐèÒªÇ×½ü¹Ø×¢×îеÄÇå¾²ÍþвºÍÎó²î£¬²¢ÊµÊ±¸üкÍÍêÉÆ·À»¤²½·¥£¬Ìá¸ßÍøÕ¾µÄÇå¾²ÐÔ¡£
ÒÔÉÏÊǹØÓÚNginxÇå¾²·À»ðǽÉèÖõÄÏÈÈÝ£¬Ï£Íû¶Ô¸÷ÈËÓÐËù×ÊÖú¡£Í¨¹ýºÏÀíµÄÉèÖúͷÀ»¤²½·¥£¬ÎÒÃÇ¿ÉÒÔ°ü¹ÜÍøÕ¾µÄÇå¾²£¬Ìṩ¸üºÃµÄÓû§ÌåÑé¡£
ÒÔÉϾÍÊÇNginxÇå¾²·À»ðǽÉèÖ㬱£»¤ÍøÕ¾²»ÊܶñÒâ¹¥»÷µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡