LinuxµÄ¹ã·ºÓ¦ÓúͿìËÙ·¢Õ¹µÃÒæÓÚ»¥ÁªÍøµÄ·ÉËÙ·¢Õ¹¡£¶ÔÓÚInternetÉÏÓ¦Óù㷺µÄWeb·þÎñÀ´Ëµ£¬Linux±íÏÖ³öÉ«¡£ºÜÄÑ˵ÇåÄ¿Ç°InternetÉϾ¿¾¹ÓжàÉÙ¸öÍøÕ¾ÔÚʹÓÃLinuxϵͳ£¬µ«ÖÚ¶àÍøÕ¾ÖвÉÓÃApache·þÎñÆ÷µÄÎÞÒÉÕ¼¾ÝÁ˼«´óµÄÊг¡·Ý¶î¡£
ÈçºÎΪÍøÕ¾Ìṩ±£»¤£¬·ÀÖ¹·Ç·¨Óû§µÇÈëÄØ£¿Í¨³£¿ÉÒÔ²ÉÓÃÉí·ÝÈÏÖ¤·½Ê½¡£Éí·ÝÈÏÖ¤ÊÇ·ÀÖ¹·Ç·¨Óû§Ê¹ÓÃ×ÊÔ´µÄÓÐЧÊֶΣ¬Ò²ÊǹÜÀí×¢²áÓû§µÄÓÐЧ·½·¨¡£ÏÖÔںܶàÍøÕ¾¶¼Ê¹ÓÃÉí·ÝÈÏÖ¤À´¹ÜÀíÓû§×ÊÔ´£¬¶ÔÓû§µÄ·ÃÎÊȨÏÞ½øÐÐÑϸñµØÏÞÖÆ¡£´«Í³µÄÉí·ÝÈÏÖ¤·½·¨ÊÇͨ¹ý¼ìÑéÓû§µÄ×¢²áÃû¡¢¿ÚÁÀ´¾ö¶¨ÊÇ·ñÔÊÐíÓû§Ê¹ÓÃ×ÊÔ´£¬µ«ÕâÖÖÈÏÖ¤·½·¨ÔÚijЩÇé¿öÏÂ×÷Óò¢²»Ê®·ÖÓÐЧ¡£ÌرðÊÇÔÚLinuxƽ̨ϵÄApache·þÎñÆ÷£¬ÍêÈ«¿ÉÒÔÓÃLinuxµÄ·½·¨À´ÊµÏÖÃÜÂëÑéÖ¤ºÍ±£»¤¡£
LinuxÏÂ×î³£¼ûµÄÃÜÂë±£»¤·½·¨ÊÇÀûÓÃ.htaccessÎļþ£¬¼´Ä¿Â¼ÅäÖÃʵÏÖÃÜÂë±£»¤£¬ÕâÒ²ÊÇ.htaccessÎļþµÄ¹¦ÄÜÖ®Ò»¡£ÕâÖÖ·½·¨¿ÉÒÔʹûÓÐÊÚȨµÄä¯ÀÀÕß²»ÄܽøÈë.htaccessÎļþËùÉèÖõÄÏÞÖÆÇøÓò¡£Ò»°ãµØ£¬Ê¹ÓÃjavascript¼¼Êõ½øÐÐÉèÖõÄÃÜÂëÌ«¼òµ¥£¬ºÜÈÝÒ׾ͱ»Æƽ⣬Ôì³ÉÁ˲»°²È«¡£¶øʹÓÃ.htaccessÎļþ±£»¤Ä¿Â¼±ÈʹÓÃÆäËü³ÌÐò£¨Java/HTML/ASP/CGI£©¸üΪÓÐЧºÍ°²È«¡£¸üÖØÒªµÄÊÇ£¬Ê¹ÓÃ.htaccessµÄ·½Ê½½øÐÐÉèÖ㬲»ÐèÒª±àд³ÌÐò¾Í¿ÉÒÔʵÏÖ£¬¾ßÌå²Ù×÷±È½ÏÈÝÒס£
ÏÂÃæ¾ÍÀ´½éÉܺÍÑÝʾLinux£«ApacheÏÂÃÜÂë±£»¤µÄ·½·¨£¬È«ÃæʵÏÖÍøÕ¾±£»¤¡£
ʲôÊÇ.htaccessÎļþ
.htaccessÎļþÊÇApache·þÎñÆ÷ÉϵÄÒ»¸öÉèÖÃÎļþ¡£ËüÊÇÒ»¸öÎı¾Îļþ£¬¿ÉÒÔʹÓÃÈκÎÎı¾±à¼Æ÷½øÐбàд¡£.htaccessÎļþÌṩÁËÕë¶ÔĿ¼¸Ä±äÅäÖõķ½·¨£¬¼´Í¨¹ýÔÚÒ»¸öÌض¨µÄÎĵµÄ¿Â¼ÖзÅÖÃÒ»¸ö°üº¬Ò»¸ö»ò¶à¸öÖ¸ÁîµÄÎļþ£¨.htaccessÎļþ£©£¬ÒÔ×÷ÓÃÓÚ´ËĿ¼¼°ÆäËùÓÐ×ÓĿ¼¡£.htaccessµÄ¹¦ÄÜ°üÀ¨ÉèÖÃÍøÒ³ÃÜÂë¡¢ÉèÖ÷¢Éú´íÎóʱ³öÏÖµÄÎļþ¡¢¸Ä±äÊ×Ò³µÄÎļþÃû£¨Èçindex.html£©¡¢½ûÖ¹¶ÁÈ¡ÎļþÃû¡¢ÖØе¼ÏòÎļþ¡¢¼ÓÉÏMIMEÀà±ð¡¢½ûÖ¹ÁÐĿ¼ÏµÄÎļþµÈ¡£
ÔÚÐèÒªÕë¶ÔĿ¼¸Ä±ä·þÎñÆ÷µÄÅäÖ㬶ø¶Ô·þÎñÆ÷ϵͳûÓÐrootȨÏÞʱ£¬Ó¦¸ÃʹÓÃ.htaccessÎļþ¡£Èç¹û·þÎñÆ÷¹ÜÀíÔ±²»Ô¸ÒâƵ·±ÐÞ¸ÄÅäÖ㬠Ôò¿ÉÒÔÔÊÐíÓû§Í¨¹ý.htaccessÎļþ×Ô¼ºÐÞ¸ÄÅäÖã¬ÓÈÆäÊÇISPÔÚһ̨»úÆ÷ÉÏÌṩ¶à¸öÓû§Õ¾µã£¬¶øÓÖÏ£ÍûÓû§¿ÉÒÔ×Ô¼º¸Ä±äÅäÖõÄÇé¿öÏ£¬Ò»°ã»á¿ª·Å²¿·Ö.htaccessµÄ¹¦ÄܸøʹÓÃÕß×ÔÐÐÉèÖá£
×¢Ò⣬.htaccessÊÇÒ»¸öÍêÕûµÄÎļþÃû£¬²»ÊÇ***.htaccess»òÆäËü¸ñʽ£¨µ±È»Ò²ÓйÜÀíÔ±°ÑÆäÉèÖóÉÆäËüÃû×Ö£¬µ«Ò»°ã¶¼ÊÇʹÓÃ.htaccess£©¡£ÁíÍ⣬ÉÏ´«.htaccessÎļþʱ£¬±ØÐëʹÓÃASC¢òģʽ£¬²¢Ê¹ÓÃchmodÃüÁî¸Ä±äȨÏÞΪ£º644£¨RW_R__R__£©¡£Ã¿Ò»¸ö·ÅÖÃ.htaccessµÄĿ¼ºÍÆä×ÓĿ¼¶¼»á±».htaccessÓ°Ïì¡£ÀýÈ磬ÔÚ/abc/Ŀ¼Ï·ÅÖÃÁËÒ»¸ö.htaccessÎļþ£¬ÄÇô/abc/ºÍ/abc/def/ÄÚËùÓеÄÎļþ¶¼»á±»ËüÓ°Ï죬µ«/index.html²»»á±»ËüÓ°Ï죬ÕâÒ»µãÊǺÜÖØÒªµÄ¡£
ʵÏÖÃÜÂë±£»¤
1.½¨Á¢.htpasswdÎļþ
Ê×ÏÈÔÚÒªÉèÖôæÈ¡¿ØÖƵÄĿ¼£¨Èçhtdocs£©Ï½¨Á¢Ò»¸öÎļþ£¬ÎļþÃû¿ÉÒÔ×ÔÐÐÉ趨£¬Ò»°ã·þÎñÆ÷¶¼»áÉèÖÃΪ.htpasswd£¬¸ÃÎļþÊDz»ÄÜÓÉHTTP¶ÁÈ¡µÄ¡£.htpasswdÎļþÖеÄÿһÐдú±íÒ»¸öʹÓÃÕߣ¬Ê¹ÓÃÕßµÄÃû×Ö¼°¾¹ý¼ÓÃܵÄÃÜÂëÒÔðºÅ£º·Ö¸ô¡£
2..htaccessÎļþʵÏÖ±£»¤
.htaccessÎļþµÄÄÚÈÝÈçÏ£º authtype basic
authuserfile /usr/home/***/htdocs/.abcname1
authgroupfile /usr/home/***/htdocs/.abcname2
authname information
require valid-user
ÆäÖеڶþÐк͵ÚÈýÐÐÖеÄ***¿ÉÒÔ¸ÄΪ¸öÈ˵ÄFTPµÇ¼Ãû¡£.abcname1ºÍ.abcname2¿ÉÒÔÊÇÈÎÒâµÄÎļþÃû£¬Èç.htpasswd¡¢.htpass£¬µ«²»ÄÜÊÇ.htaccess¡£½«.htaccessÉÏ´«µ½Òª½øÐÐÃÜÂë±£»¤µÄĿ¼£¨Èçhtdocs£©ÖС£
.htaccessÎļþ×îºóµÄ¡°require¡±¸æËß·þÎñÆ÷ÄÄЩÓû§¿ÉÒÔ½øÈë¡£require valid-userÊÇÖ¸Ö»ÒªÊÇ.htpasswdÖеÄÈκÎÒ»¸ö¶¼¿ÉÒÔ½øÈë¡£Ò²¿ÉÒÔÖ¸¶¨Ãûµ¥ÉϵÄijÈË»òij¼¸ÈË¿ÉÒÔͨ¹ý£¬Ê¹ÓÃrequire user username»òrequire user username1 username2 username3¡£»¹¿ÉÒÔÖ¸¶¨Ä³×éÈË¿ÉÒÔͨ¹ý£¬Ê¹ÓÃrequire group groupname¡£
3.Ôö¼ÓеÄÐí¿ÉÓû§
½øÈëhtdocsĿ¼£¬ÔÚÃüÁîÐÐ״̬ÊäÈëÒÔÏÂÃüÁîÉú³É.abcname1Îļþ¡£ echo > .abcname1
/var/www/bin/htpasswd .abcname1 abc
abc±íʾҪÔö¼ÓµÄÓû§Ãû¡£ÊäÈë´ËÃüÁîºó£¬ÏµÍ³»áÌáʾÊäÈë´ËÓû§ÃÜÂ룬ÕâÑù¸ÃÓû§Ãû¾ÍÉúЧÁË¡£ÒÔºóÈçÒªÔÙÔö¼ÓÓû§£¬ÔËÐеڶþÐеÄÃüÁîʱ»»Ò»¸öÓû§Ãû¼´¿É¡£Èç¹ûÕâ¸öÓû§Ãû´æÔÚ£¬Ôò»áÌáʾÐÞ¸ÄÃÜÂë¡£
4.½¨Á¢ÔÊÐí·ÃÎʵÄ×é
×éµÄÉèÖ÷½·¨Êǽ¨Á¢Ò»¸öÃûΪ.htgroupµÄÎı¾Îļþ£¬ÄÚÈÝÈçÏ£º groupname1: username1 username2 username3
groupname2: username1 username3 username4
²¢ÔÚ.htaccessÖмÓÉÏ¡°AuthGroupFile /absolute/path/.htgroup¡±¡£ÒÔASC¢òģʽÉÏ´«ËùÓÐÎļþºó£¬¸ÃĿ¼ÖеÄËùÓÐÎļþ¶¼»á±»±£»¤ÆðÀ´¡£
ÉèÖôíÎóÎļþ
Èç¹ûÏ£ÍûÔÚÕÒ²»µ½Îļþʱ²»³öÏÖ¡°ÕÒ²»µ½ÍøÒ³¡±µÄÒ³ÃæÌáʾ£¬¶øÊÇ´ò¿ªÁíÒ»¸öHTMLÎļþ£¬·½·¨Ò²ºÜ¼òµ¥¡£Ê×Ïȱàдһ¸öеÄÒ³Ã棬ȻºóÓÃÎı¾±à¼Æ÷´ò¿ª.htaccess£¬ÔÚÎļþ×îºó¼ÓÉÏ£ºErrordocument.nbsp404 404.html¡£ÕâÀ404.htmlÊÇ´íÎóÎļþµÄÃû×Ö£¬¼´ËùÏÔʾµÄÒ³Ã棻404ÊÇ´íÎó´úÂë¡£Ò»°ã³£¼ûµÄ´íÎó´úÂëºÍËù´ú±íµÄ´íÎóÔÒòÈçÏ£º 401 Authorization failed ÊÚȨʧ°Ü£¬¼´ÃÜÂë´íÎó¡£
403 Access denied ´æÈ¡´íÎ󣬼´²»¿ÉÒÔ¶ÁÈ¡¸ÃÎļþ¡£
404 File not found ÕÒ²»µ½Îļþ¡£
500 Internal Server Error
·þÎñÆ÷ÄÚ²¿´íÎ󣬿ÉÄÜÊÇWeb·þÎñÆ÷±¾Éí´æÔÚÎÊÌ⣬Ҳ¿ÉÄÜÊDZàдµÄ³ÌÐò³ö´í¡£
½ûÖ¹¶ÁÈ¡Îļþ
Èç¹û½«Ä³Ð©ÄÚÈÝÈçÃÜÂ룬´æ·ÅÔÚÒ»¸öÎļþÖУ¬ÄÇô±ðÈËÖ»ÐèÖªµÀ¸ÃÎļþµÄ¶ÔӦλÖ㬾ͿÉÒÔһĿÁËÈ»£¬ÕâÑùÌ«²»°²È«¡£ÆäʵÍêÈ«¿ÉÒÔ²»¸Ä±äÆäËüÉèÖã¬Ò²²»Óý«ÎļþÒƵ½ÆäËüµØ·½¾Í¿É½â¾öÕâ¸öÎÊÌ⣬ֻÐèÔÚ.htaccessÎļþÖмÓÈëÒÔϼ¸ÐУº
order allow,deny
deny from all
Èç¹ûϵͳ°²×°µÄÊÇApache 1.3ÒÔºóµÄ°æ±¾£¬¸ü¿ÉÒÔÖ§³Öregular expressionµÄfilesmatch¡£
order allow,deny
deny from all
filesºÍfilesmatch±íʾֻ¶Ô·ûºÏÒªÇóµÄ²¿·ÖÎļþÉúЧ¡£¡°order deny£¬allow¡±±íʾÏÈÕÒ³ö½ûÖ¹£¨deny£©µÄ£¬È»ºóÈ¥ÕÒÐí¿ÉµÄ£¨allow£©¡£Èç¹û½«ËüÃǵÄ˳Ðòµßµ¹¡°order allow£¬deny¡±Ôò±íʾÏÈÕÒ³öÐí¿ÉµÄ£¬ºó²ÅÈ¥ÕÒ½ûÖ¹µÄ¡£¡°deny from all¡±Ôò±íʾȫ²¿IPµØÖ·¶¼²»Ðí¿É¡£Ïà¶ÔµØ£¬¡°allow from all¡±±íʾȫ²¿¶¼ÔÊÐí¡£¿ÉÒÔÕâÑùÉèÖ㺠order allow,deny
allow from all
deny from 111.222
deny from 111.222ÊÇÖ¸½ûÖ¹ËùÓÐÒÔ111.222¿ªÊ¼µÄIPµØÖ·£¨Èç111.222.0.1£©¡£³ýÁËÉèÖÃIPµØÖ·Í⣬Ҳ¿ÉÒÔÉèÖóÉhostname£¨È磺***.com£©¡£¡°Files¡±ºÍ¡°Filesmatch¡±µÄÓÃ;ºÜ¶à£¬²»µ«¿ÉÒÔÉèÖÃdeny£¬Ò²¿ÉÒÔÉèÖøö±ðÎļþµÄÃÜÂ룬È磺
require user 123
require user abc
ʹÓÃ.htaccessÎļþÒ²»á´æÔÚһЩÎÊÌ⣬±ÈÈçÐÔÄÜ¡£Èç¹ûʹÓÃ.htaccessÎļþ£¬ÔòApacheÐèÒªÔÚÿ¸öĿ¼ÖвéÕÒ¸ÃÎļþ£¬»¹±ØÐëÔÚËùÓиü¸ß¼¶µÄĿ¼ÖвéÕÒËü£¬ÁíÍ⣬ÿ´ÎÇëÇóÒ»¸öÒ³Ãæʱ£¬Ò²¶¼ÐèÒª¶ÁÈ¡.htaccessÎļþ¡£Òò´Ë£¬ÔÊÐíʹÓÃ.htaccessÎļþ¶¼»áµ¼ÖÂÐÔÄܵÄϽµ¡£
ÀýÈ磬¶Ô/usr/hq/htdocsÖÐÒ³ÃæµÄÇëÇó£¬Apache±ØÐë²éÕÒÒÔÏÂÎļþ£º /.htaccess
/usr/.htaccess
/usr/hq/.htaccess
/usr/hq/htdocs/.htaccess
×ܵÄÀ´Ëµ£¬Í¨¹ý.htaccessÀ´±£»¤ÍøÕ¾¸üΪ·½±ãºÍ°²È«¡£ÒòΪËü²»ÏñÀûÓóÌÐòʵÏÖÃÜÂë±£»¤Ê±£¬ÓпÉÄÜͨ¹ý²Â²âµÄ·½·¨»ñÈ¡ÃÜÂë¡£ÀûÓÃ.htaccessÎļþʵÏÖÃÜÂë±£»¤£¬Ò»°ãÊǺÜÄÑÆƽâµÄ¡£¼øÓÚ.htaccess·½Ê½µÄÓÅȱµã£¬¶ÁÕß¿ÉÒÔ¸ù¾Ý¾ßÌåµÄÇé¿öÑ¡ÔñÊʺϵķ½·¨À´±£Ö¤ÍøÕ¾µÄ°²È«¡£
sgh2005 ÓÚ 2005-10-29 01:17:43·¢±í:
ÊܽÌÁË
linux_ ÓÚ 2005-10-02 00:25:53·¢±í:
ºÇºÇ£¬²»´í£¬ÊܽÌÁË
aini ÓÚ 2005-09-20 00:21:47·¢±í:
²»´í