标签:
apache2.2.x版本
1. 注释主配置文件/etc/httpd/conf/httpd.conf中的 DoucumentRoot
#DocumentRoot "/var/www/html"
2.把主配置文件NameVirtualHost前面注释去掉,添加本地主机名称
NameVirtualHost 192.168.136.131:80
3.如果注释了ServerName,或者默认为localahost:80或者127.0.0.1:80则会报错,但不影响虚拟主机的使用
"Stopping httpd: [ OK ] Starting httpd: httpd: Could not reliably determine the server‘s fully qualified domain name, using ::1 for ServerName [ OK ]
4.在主配置文件下面添加虚拟主机的配置文件
<VirtualHost 192.168.136.131:80> //本地主机名称 ,这个基于用户认证登录 DocumentRoot /var/www/virtual/test1 //网站根目录 ServerName www.test1.com //域名1 ErrorLog logs/error_logs //错误日志地址 CustomLog logs/custom_logs combined //常规日志,combined类型记录 <Directory /var/www/virtual/test1/> //配置网站目录权限 Options None #AllowOverRide None AllowOverride AuthConfig //添加基用户认证登录配置 AuthType Basic AuthName "test" AuthUserFile "/etc/httpd/conf/htpasswd" //认证用户密码存放位置 Require user test //只允许test登录 Order allow,deny //允许所有用户访问 allow from all </Directory> </VirtualHost> <VirtualHost 192.168.136.131:80> //常规配置 ServerAdmin sean@test.com //域名2 DocumentRoot /var/www/virtual/test2/ ServerName www.test2.com ErrorLog logs/error_logs </VirtualHost>
然后重启httpd
httpd2.4.x版本
1.主配置文件只需要把VirtualHost下面Incalude一行去掉注释即可
# Virtual hosts
Include /etc/httpd/extra/httpd-vhosts.conf
2.配置/etc/httpd/extra/httpd-vhost.conf
<VirtualHost *:80> //这里不要填写127.0.0.1或者localhost,可以用 “*“ 或者本机的 内网IP外网IP ServerAdmin admin@test.com DocumentRoot "/usr/local/apache/htdocs/www.a.org" ServerName "www.a.org" DirectoryIndex index.html index.php ErrorLog "logs/www.a.org-error_log" CustomLog "logs/www.a.org-access_log" combined </VirtualHost> <VirtualHost *:80> ServerAdmin admin@test.com DocumentRoot "/usr/local/apache/htdocs/www.b.org" ServerName "www.b.org" DirectoryIndex index.html index.php ErrorLog "logs/www.b.org-error_log" CustomLog "logs/www.b.org-access_log" combined </VirtualHost>
3.重启服务
标签:
原文地址:http://www.cnblogs.com/kankanhua/p/4658417.html