假定项目工程路径为:/var/www/yiitest
域名为:yiitest.com
1.在 /etc/apache2/sites-available 目录中建立文件yiitest,并编辑该文件,内容如下:
3.重启服务器
>>>>>>>>>>>>>>>
应用一:Basic认证模式
在项目工程目录 /var/www/yiitest 下面创建文件 .htaccess ,内容如下:
>>>>>>>>>>>>>>>
应用二:不显示服务器文件列表
在不需要显示文件列表的目录下创建 .htaccess ,内容如下:
域名为:yiitest.com
1.在 /etc/apache2/sites-available 目录中建立文件yiitest,并编辑该文件,内容如下:
<VirtualHost *:80>
ServerName yiitest.com
ServerAdmin webmaster@yiitest.com
DocumentRoot /var/www/yiitest
ErrorLog /var/www/yiitest_error.log
CustomLog /var/www/yiitest_access.log combined
</VirtualHost>
2.运行命令,建立链接
a2ensite yiitest
此时在/etc/apache2/sites-enabled/目录中发现多了一个yiitest的软链接。
3.重启服务器
/etc/init.d/apache2 restart
>>>>>>>>>>>>>>>
应用一:Basic认证模式
在项目工程目录 /var/www/yiitest 下面创建文件 .htaccess ,内容如下:
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options -Indexes
AuthUserFile /var/www/yii/.htpasswd
AuthGroupFile /dev/null
AuthName "Please enter your ID and password"
AuthType Basic
require valid-user
order deny,allow
创建登录用户:
htpasswd -bc /var/www/htaccess/.htpasswd shou test1234
※用户名shou、密码test1234
>>>>>>>>>>>>>>>
应用二:不显示服务器文件列表
在不需要显示文件列表的目录下创建 .htaccess ,内容如下:
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options -Indexes
order deny,allow
※使用.htaccess的条件(Ubuntu下的配置):
1.mod_rewrite模块开启
less /etc/apache2/mods-available/rewrite.load
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
2.将工作目录下面的AllowOverride None改为AllowOverride All
less /etc/apache2/sites-available/default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>