标签:固定 额外 3.1 修改dns document 软件包 min 网站服务器 util
一、httpd服务的访问控制Apache-2.2.x
Deny,allow:先“拒绝”后“允许”,默认允许所有未明确拒绝的客户机地址
使用Allow from和Deny from配置项时,需要设置客户机地址以构成完整的限制策略,地址的形式可以是IP地址、网络地址、主机名或域名,使用名称“all”时表示任意地址。限制策略格式如下
Deny from address1 address2 ...
Allow from address1 address2 ...
<Directory “/usr/local/httpd/htdocs”>
.. //省略部分内容
Order Allow,deny
Allow from all
</Directory>
<Directory “/usr/local/awstats/wwwroot:”>
... //省略部分内容
Order allow,deny //先允许后拒绝
Allow from 173.17.17.173 //只允许此IP访问
</Directory>
<Directory “/usr/local/awstats/wwwroot”>
... //省略部分内容
Order deny,allow
Deny from 192.168.0.0/24 192.168.1.0/24
</Directory>
当通过未被授权的客户机访问网站目录时,将会被拒绝访问
Apache-2.4.x
(1)允许所有
Require all granted
(2)拒绝所有
Require all denied
(3)只允许指定IP访问
Require ip <允许的IP地址>
(4)只拒绝指定IP访问
<RequireAll>
Require all granted
Require not ip xxx
</RequireAll>
例:
(1)创建用户认证数据文件
cd /usr/local/httpd //进入httpd安装目录方便执行命令
bin/htpasswd -c /usr/local/httpd/conf/.awspwd webadmin //创建用户账号webadmin(只能用于登录web界面)
cat /usr/local/httpd/conf/.awspwd //查看用户账号数据文件
bin/htpasswd /usr/local/httpd/conf/.awspwd tsengyia
cat /usr/local/httpd/conf/.awspwd
(2)添加用户授权配置
vim /usr/local/httpd/conf/httpd.conf
<Directory "/usr/local/awstats/wwwroot">
···
AuthName "AWStats Directory"
AuthType Basic
AuthUserFile /usr/local/httpd/conf/.awspwd
require valid-user
</Directory>
注释
AuthName:定义受保护的领域名称,该内容将在浏览器弹出的认证对话框中显示
AuthType:设置认证的类型,Basic表示基本认证
AuthUserFile:设置用户保存用户账号、密码的认证文件路径
required valid-user:要求只有认证文件中的合法用户才能访问。其中valid-user表示所有合法用户,若只授权给单个用户,可改为指定的用户名(如require user webadmin)
(3)验证用户访问授权
(1)为虚拟主机提供域名解析(搭建DNS,测试使用)
yum -y install bind bindg -chroot bind-utils //安装bind软件包
vim /etc/named.conf //修改named服务主配置文件
cp /var/named/named.empty /var/named/hiahia.org.zone //拷贝模板文件
vim /var/named/hiahia.org.zone //编辑正向解析文件
chown named:named /var/named/hiahia.org.zone //设置文件属主和属组为named
/etc/init.d/named start && 8mchkconfig --level 35 named on
(2)为虚拟主机准备网页文档
每个虚拟Web主机准备网站目录及网页文档。
mkdir -p /usr/local/httpd/htdocs/www
mkdir -p /usr/local/httpd/htdocs/blog
echo "<h1>www.xueluo.org</h1>">/usr/local/httpd/htdocs/www/index.html
echo "<h1>blog.xueluo.org</h1>">/usr/local/httpd/htdocs/blog/index.html
(3)添加虚拟主机配置
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
<Directory "/usr/local/httpd/htdocs/">
Order allow,deny
Allow from all
(httpd2.4.x这里的两行换成Require all granted)
</Directory>
<VirtualHost 192.168.1.151>
DocumentRoot "/usr/local/httpd/htdocs/www"
ServerName www.hiahia.com
ErrorLog "logs/www.hiahia.com_error_log"
CustomLog "logs/www.hiahia.com_access_log" common
</VirtualHost>
<VirtualHost 192.168.1.151>
DocumentRoot "/usr/local/httpd/htdocs/blog"
ServerName blog.hiahia.com
ErrorLog "logs/blog.hiahia.com_error_log"
CustomLog "logs/blog.hiahia.com_access_log" common
</VirtualHost>
vim /usr/local/httpd/conf/httpd.conf
Include conf/extra/httpd-vhosts.conf //删除开头#号,读取虚拟主机配置文件
/etc/init.d/httpd restart
(4)客户机中访问虚拟Web主机
(1)添加虚拟接口IP或新增加网卡配置IP地址
(2)添加虚拟主机配置
vim /var/named/xueluo.org.zone //修改dns正向解析文件,更改其中一个IP地址为新增网卡IP
/etc/init.d/named restart //重启namd服务
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
<Directory "/usr/local/httpd/htdocs/">
Order allow,deny
Allow from all
(httpd2.4.x这里的两行换成Require all granted)
</Directory>
<VirtualHost 192.168.1.151>
DocumentRoot "/usr/local/httpd/htdocs/www"
ServerName www.hiahia.com
ErrorLog "logs/www.hiahia.com_error_log"
CustomLog "logs/www.hiahia.com_access_log" common
</VirtualHost>
<VirtualHost 192.168.1.152>
DocumentRoot "/usr/local/httpd/htdocs/blog"
ServerName blog.hiahia.com
ErrorLog "logs/blog.hiahia.com_error_log"
CustomLog "logs/blog.hiahia.com_access_log" common
</VirtualHost>
/etc/init.d/httpd restart //重启httpd服务
(3)客户机访问虚拟Web
(1)添加虚拟主机配置
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf
<Directory "/usr/local/httpd/htdocs/">
Order allow,deny
Allow from all
(httpd2.4.x这里的两行换成Require all granted)
</Directory>
<VirtualHost 192.168.1.100:80>
DocumentRoot "/usr/local/httpd/htdocs/www"
ServerName www.xueluo.org
ErrorLog "logs/www.xueluo.org_error_log"
CustomLog "logs/www.xueluo.org_access_log" common
</VirtualHost>
<VirtualHost 192.168.1.200:81>
DocumentRoot "/usr/local/httpd/htdocs/blog"
ServerName blog.xueluo.org
ErrorLog "logs/blog.xueluo.org_error_log"
CustomLog "logs/blog.xueluo.org_access_log" common
</VirtualHost>
(2)加载额外配置文件,并设置监听端口
vim /usr/local/httpd/conf/httpd.conf
Listen 192.168.1.151:999
Listen 192.168.1.152:888
/etc/init.d/httpd restart
(3)客户机访问虚拟Web
标签:固定 额外 3.1 修改dns document 软件包 min 网站服务器 util
原文地址:http://blog.51cto.com/13770206/2152338