在这里让我们一起学习,一起提高!
一.基本的Apache用户认证方法:
若对某一目录下的文件如/home/ftp/pub需要做到用户认证,则在httpd.conf
中加入下面的行
<>
options indexes followsymlinks
allowoverride authconfig
order allow,deny
allow from all
<>
用在目录/home/ftp/pub下放文件.htaccess,内容如下:
authname "shared files"
authtype basic
authuserfile /etc/.passwd
require valid-user
用随Apache来的程序htpasswd 生成文件/etc/.passwd,每行一个用户名:密码
只要能提供正确的用户名和密码对,就允许登录访问,这是针对任何地址来的
请求都要求提供用户名和密码认证。
二.针对部分网段或地址要求认证。
若对某一目录下的文件如/home/ftp/pub需要做到用户认证,则在httpd.conf
中加入下面的行
<>
options indexes followsymlinks
allowoverride authconfig
order allow,deny
allow from all
<>
用在目录/home/ftp/pub下放文件.htaccess,内容如下:
authname "shared files"
authtype basic
authuserfile /etc/.passwd
require valid-user
用随Apache来的程序htpasswd 生成文件/etc/.passwd,每行一个用户名:密码
只要能提供正确的用户名和密码对,就允许登录访问,这是针对任何地址来的
请求都要求提供用户名和密码认证。
二.针对部分网段或地址要求认证。
本例中设定/opt的虚拟目录,并采用.htaccess文件实现对/opt虚拟目录的用户认证
1.修改/etc/httpd/conf/httpd.conf
DocumentRoot "/backup"
Alias /html/ "/var/www/html"
Alias /opt "/opt" #定义/opt虚拟目录
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Options Indexes FollowSymLinks
AllowOverride authconfig # allowoverride authconfig一行表示允许对/opt目录下的文件进行用户认证。
1.修改/etc/httpd/conf/httpd.conf
DocumentRoot "/backup"
Alias /html/ "/var/www/html"
Alias /opt "/opt" #定义/opt虚拟目录
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.
#
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Options Indexes FollowSymLinks
AllowOverride authconfig # allowoverride authconfig一行表示允许对/opt目录下的文件进行用户认证。
允许用户浏览目录
<Directory "D:/Server/hick">
Options ALL
AllowOverride None
Order allow,deny
Allow from all
</Directory>
文件访问控制
<Directory "C:/hick">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Apache服务器可以针对目录进行文档的访问控制,访问控制可以通过两种方式来实现,一个是在设置文件 httpd.conf(或access.conf)中针对每个目录进行设置,另一个方法是在每个目录下设置访问控制文件,通常访问控制文件名字为.htaccess。虽然使用这两个方式都能用于控制浏览器的访问,然而使用配置文件的方法要求每次改动后重新启动httpd守护进程,比较不灵活,因此主要用于配置服务器系统的整体安全控制策略,而使用每个目录下的.htaccess文件设置具体目录的访问控制更为灵活方便。
<Directory "D:/Server/hick">
Options ALL
AllowOverride None
Order allow,deny
Allow from all
</Directory>
文件访问控制
<Directory "C:/hick">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Apache服务器可以针对目录进行文档的访问控制,访问控制可以通过两种方式来实现,一个是在设置文件 httpd.conf(或access.conf)中针对每个目录进行设置,另一个方法是在每个目录下设置访问控制文件,通常访问控制文件名字为.htaccess。虽然使用这两个方式都能用于控制浏览器的访问,然而使用配置文件的方法要求每次改动后重新启动httpd守护进程,比较不灵活,因此主要用于配置服务器系统的整体安全控制策略,而使用每个目录下的.htaccess文件设置具体目录的访问控制更为灵活方便。
和使用.htaccess文件实现用户认证有所不同,主要不同之处如下:
采用.htaccess文件认证目录关键配置如下:
AllowOverride authconfig
本文中的认证目录关键配置如下:
AuthType Basic #定义认证区域和名称
AuthName "VSS"
AuthUserFile C:PASSWDpasswd #定义认证文件名
require user tyl test
#DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"
DocumentRoot "D:/vss" #修改root文件夹
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
采用.htaccess文件认证目录关键配置如下:
AllowOverride authconfig
本文中的认证目录关键配置如下:
AuthType Basic #定义认证区域和名称
AuthName "VSS"
AuthUserFile C:PASSWDpasswd #定义认证文件名
require user tyl test
#DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"
DocumentRoot "D:/vss" #修改root文件夹
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#