canvas教程

【linux apache虚拟主机配置(基于ip,端口,域名)(2)

字号+ 作者:H5之家 来源:H5之家 2017-11-15 13:07 我要评论( )

VirtualHost 192.168.1.2:80 ServerName DocumentRoot "/www/7mxt.net" VirtualHost 192.168.1.2:80 ServerName DocumentRoot "/www/7mxt.net" CustomLog /var/log/httpd/7mxt.net/access_log combined Directory "

<VirtualHost 192.168.1.2:80>
ServerName
DocumentRoot "/www/7mxt.net"

<VirtualHost 192.168.1.2:80>
ServerName
DocumentRoot "/www/7mxt.net"
CustomLog /var/log/httpd/7mxt.net/access_log combined
<Directory "/www/7mxt.net">
Options none
AllowOverride none
Order deny,allow
Deny from 192.168.1.100
</Directory>
</VirtualHost>

<VirtualHost 192.168.1.2:8080>
ServerName
DocumentRoot "/www/abc.net"
</VirtualHost>

 

1,这个域名下面的Directory配置为   需要用户验证,支持3种情况的配置:

。只允许某个用户访问

。只允许文件中的用户

。只允许组文件中定义的用户

AllowOverride AuthConfig:  需要授权
AuthType Basic:基本授权
AuthName "Restricted Site..." :授权说明
AuthUserFile "/etc/httpd/conf/htpasswd"   :  需要授权的用户 保存在这个文件中,这个文件中的内容用

htpasswd这个命令创建,第一次带参数c表示创建,第二次不需要带c

htpasswd -c -m /etc/httpd/conf/htpasswd ghost
htpasswd -m /etc/httpd/conf/htpasswd ghostwu

AuthGroupFile "/etc/httpd/conf/htgroup": 需要授权的用户保存在这个文件中

#Require user ghost:只允许ghost这个用户登录

Require group myusers: 只允许myusers这个组中的用户登录
#Require valid-user:只允许htpasswd这个文件中定义的用户登录

 

[root@centos64Study conf]# ls
htgroup htpasswd httpd.conf httpd.conf.bak magic
[root@centos64Study conf]# cat htgroup
myusers: ghost ghostwu
[root@centos64Study conf]# cat htpasswd
ghost:$apr1$IeKI2YLO$RX8EjYBoHbMzCkHocFK0l/
ghostwu:$apr1$LoA/O0i0$0/EJu3xTXo2yCMimMUAcQ.

2,CustomLog /var/log/httpd/7mxt.org/access_log combined

自定义访问日志的文件路径,【注意:需要在/var/log/httpd下面存在7mxt.org这个目录】

3,

<Directory "/www/7mxt.net">
Options none
AllowOverride none
Order deny,allow
Deny from 192.168.1.100
</Directory>

这个配置针对的是7mxt.net,禁止192.168.1.100访问7mxt.net,其他的ip都允许

 


请注意,本站信息均收集自互联网,相关信息仅供参考,医疗等重要信息请以正规途径为最终意见,本站不承担任何责任!

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
网友点评