LinuxЧÀÍÆ÷Çå¾²ÐÔ£ºWeb½Ó¿Ú±£»¤Õ½ÂÔµÄÒ»Á¬Ñݽø¡£
LinuxЧÀÍÆ÷Çå¾²ÐÔ£ºWeb½Ó¿Ú±£»¤Õ½ÂÔµÄÒ»Á¬Ñݽø
Ëæ×Å»¥ÁªÍøµÄÆÕ¼°ºÍÉú³¤£¬WebÓ¦ÓóÌÐòµÄʹÓÃÒѾ³ÉΪÎÒÃÇÒ»Ñùƽ³£ÉúÑĺÍÊÂÇéµÄÖ÷Òª×é³É²¿·Ö¡£È»¶ø£¬ËæÖ®¶øÀ´µÄÊÇWebÇå¾²ÎÊÌâµÄÈÕÒæÍ»³ö¡£ÎªÁ˱£»¤Ð§ÀÍÆ÷ºÍÓû§Êý¾ÝµÄÇå¾²£¬ÎÒÃÇÐèÒªÒ»Ö±ÌáÉýLinuxЧÀÍÆ÷µÄÇå¾²ÐÔ£¬²¢½ÓÄÉÓÐÓõÄÕ½ÂÔÀ´±£»¤Web½Ó¿Ú¡£
±¾ÎĽ«Ì½ÌÖLinuxЧÀÍÆ÷ÖеÄWeb½Ó¿Ú±£»¤Õ½ÂÔ£¬²¢Õ¹Ê¾Ò»Ð©³£¼ûµÄ´úÂëʾÀý¡£
¸üÐÂÈí¼þ°üºÍ²Ù×÷ϵͳ
°´ÆÚ¸üÐÂЧÀÍÆ÷ÉϵÄÈí¼þ°üºÍ²Ù×÷ϵͳÊÇÒ»ÖÖ»ù±¾µÄЧÀÍÆ÷Çå¾²²½·¥¡£Í¨¹ýʵʱװÖÃ×îеÄÇå¾²²¹¶¡ºÍ¸üУ¬¿ÉÒÔÐÞ¸´ÒÑÖªµÄÎó²î²¢Ìá¸ßЧÀÍÆ÷µÄÇå¾²ÐÔ¡£ÒÔÏÂÊÇÔÚDebian/UbuntuÉϸüÐÂÈí¼þ°üµÄʾÀý´úÂ룺
sudo apt update sudo apt upgrade
µÇ¼ºó¸´ÖÆ
ÉèÖ÷À»ðǽ
·À»ðǽÊÇЧÀÍÆ÷Çå¾²µÄµÚÒ»µÀ·ÀµØ¡£Í¨¹ýÉèÖ÷À»ðǽ¹æÔò£¬¿ÉÒÔÏÞÖÆ´ÓÍⲿ»á¼ûЧÀÍÆ÷µÄÁ÷Á¿£¬´Ó¶ø×èֹDZÔڵĹ¥»÷¡£ÒÔÏÂÊÇʹÓÃiptablesÉèÖ÷À»ðǽ¹æÔòµÄʾÀý´úÂ룺
sudo iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT sudo iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT sudo iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT sudo iptables -A INPUT -j DROP sudo iptables -A OUTPUT -j DROP
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂ뽫ÔÊÐí´ÓÍⲿ»á¼ûHTTP£¨¶Ë¿Ú80£©ºÍSSH£¨¶Ë¿Ú22£©£¬²¢ÇҾܾøÆäËûËùÓд«ÈëºÍ´«³öµÄÁ÷Á¿¡£
ʹÓÃSSL/TLS±£»¤Êý¾Ý´«Êä
ΪÁËÈ·±£Êý¾ÝÔÚ´«ÊäÀú³ÌÖеÄÇå¾²ÐÔ£¬ÎÒÃDZØÐèʹÓÃSSL/TLSÐÒé¼ÓÃÜWeb½Ó¿ÚµÄ´«Êä¡£ÒÔÏÂÊÇʹÓÃNginxÉèÖÃSSLÖ¤ÊéµÄʾÀý´úÂ룺
server { listen 443 ssl; server_name example.com; ssl_certificate /etc/nginx/ssl/example.com.crt; ssl_certificate_key /etc/nginx/ssl/example.com.key; location / { # Web½Ó¿ÚÉèÖÃ } }
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂ뽫¼àÌýHTTPS£¨¶Ë¿Ú443£©ÇëÇ󣬲¢ÎªÐ§ÀÍÆ÷ÌṩSSLÖ¤ÊéºÍ˽Կ¡£
ÉèÖûá¼û¿ØÖÆ
ΪÁËÏÞÖƶÔWeb½Ó¿ÚµÄ»á¼û£¬ÎÒÃÇ¿ÉÒÔʹÓûùÓÚIPµØµãµÄ»á¼û¿ØÖÆÁÐ±í£¨ACL£©»òʹÓÃÓû§ÃûºÍÃÜÂë¾ÙÐÐÉí·ÝÑéÖ¤¡£ÒÔÏÂÊÇʹÓÃApacheÉèÖûùÓÚIPµØµãµÄ»á¼û¿ØÖÆÁбíµÄʾÀý´úÂ룺
<Directory "/var/www/html"> Order deny,allow Deny from all Allow from 192.168.0.0/24 </Directory>
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂ뽫ÔÊÐíÀ´×Ô192.168.0.0/24Íø¶ÎµÄIPµØµã»á¼ûWeb½Ó¿Ú¡£
ʵÑéÇ¿ÃÜÂëÕ½ÂÔ
ʹÓÃÇ¿ÃÜÂëÊDZÜÃâ¶ñÒâÓû§¾ÙÐÐÃÜÂëÍƲâºÍ±©Á¦ÆƽâµÄÖ÷Òª²½·¥¡£ÒÔÏÂÊÇʹÓÃPAM£¨Pluggable Authentication Modules£©ÉèÖÃÇ¿ÃÜÂëÕ½ÂÔµÄʾÀý´úÂ룺
password required pam_cracklib.so retry=3 minlen=8 dcredit=-1 ucredit=-1 ocredit=-1 lcredit=-1
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂ뽫ҪÇóÃÜÂëÖÁÉÙÓÐ8¸ö×Ö·û£¬²¢ÇÒ±ØÐè°üÀ¨¾Þϸд×Öĸ¡¢Êý×ÖºÍÌØÊâ×Ö·û¡£
×ÛÉÏËùÊö£¬±£»¤LinuxЧÀÍÆ÷ÖеÄWeb½Ó¿ÚÊÇÈ·±£Ð§ÀÍÆ÷ºÍÓû§Êý¾ÝÇå¾²µÄÖ÷Òª²½·¥¡£Í¨¹ý¸üÐÂÈí¼þ°üºÍ²Ù×÷ϵͳ¡¢ÉèÖ÷À»ðǽ¡¢Ê¹ÓÃSSL/TLS¼ÓÃÜ´«Êä¡¢ÉèÖûá¼û¿ØÖƺÍʵÑéÇ¿ÃÜÂëÕ½ÂÔ£¬ÎÒÃÇ¿ÉÒÔÔöǿЧÀÍÆ÷µÄÇå¾²ÐÔ¡£Í¬Ê±£¬±¾ÎÄËùÌṩµÄ´úÂëʾÀýÒ²¿ÉÒÔ×ÊÖú¶ÁÕßÏàʶÔõÑùʵÑéÕâЩսÂÔ¡£
×¢ÖØ£º±¾ÎÄÖÐËùʾµÄ´úÂë½öÓÃÓÚÑÝʾĿµÄ£¬¿ÉÄÜÐèҪƾ֤ÏêϸÇéÐξÙÐÐÐ޸ĺ͵÷½â¡£½¨ÒéÔÚÏÖÕæÏàÐÎÖÐʹÓÃʱÉóÉ÷²Ù×÷£¬²¢×ñÕÕ×î¼Ñʵ¼ùºÍÇå¾²½¨Òé¡£
ÒÔÉϾÍÊÇLinuxЧÀÍÆ÷Çå¾²ÐÔ£ºWeb½Ó¿Ú±£»¤Õ½ÂÔµÄÒ»Á¬Ñݽø¡£µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡