1、允许使用rewrite模块
#a2enmod rewrite
*会出现的问题:
perl: warning: Setting locale failed. perl: warning: Please check that your locale settings: LANGUAGE = (unset), LC_ALL = (unset), LC_CTYPE = "UTF-8", LANG = "en_US.UTF-8" are supported and installed on your system. perl: warning: Falling back to a fallback locale ("en_US.UTF-8"). Module rewrite already enabled
*解决方案:
安装 multipath-tools
#apt-get install multipath-tools
Generating locales
Missing locales are generated with locale-gen:
#locale-gen en_US.UTF-8
Alternatively, a locale file can be created manually with localedef:[1]
#localedef -i en_US -f UTF-8 en_US.UTF-8
Setting Locale Settings
The locale settings can be set (to en_US.UTF-8 in the example) as follows:
#export LANGUAGE=en_US.UTF-8 #export.UTF-8 #export LC_ALL=en_US.UTF-8 #locale-gen en_US.UTF-8 #dpkg-reconfigure locales
The dpkg-reconfigure locales command will open a dialog under Debian for selecting the desired locale. This dialog will not appear under Ubuntu. The Configure Locales in Ubuntu article shows how to find the information regarding Ubuntu.
2、创建.htpasswd文件:
http://www.luft.co.jp/cgi/htpasswd.php
*创建密码后,创建.htpasswd文件,输入创建后生成的秘文:
例如:admin:oGF.aXBiBIUTM //ID为admin,密码为1111111 的密文
*创建密码文件后在.htacess文件中输入以下:
AuthType Basic AuthName "Input your ID and Password." AuthUserFile /var/www/html/.htpasswd require valid-user
3、最终还是无法解析.htacess文件的原因:
*如果是直接使用的默认apache配置,则需改/etc/apache2/apache2.conf部分配置与以下一致即可:
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>
*主要是 AllowOverride All, 如果是AllowOverride Denny 则无法解析.htacess文件。