127.0.0.1 blog.king.org
127.0.0.1 bbs.king.org
在httpd.conf中启动httpd-vhosts.conf
Include conf/extra/httpd-vhosts.conf
添加一下内容,对虚拟主机的目录授权
<Directory "/var/www/web">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory "/var/www/bbs">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory "/var/www/blog">
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
2.在conf/extra/httpd-vhosts.conf中添加以下内容
<VirtualHost *:80>
ServerAdmin 185604832@qq.com
DocumentRoot "/var/www/web"
ServerName www.king.org
ServerAlias king.org
ErrorLog "logs/web-error_log"
CustomLog "logs/web-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin 185604832@qq.com
DocumentRoot "/var/www/bbs"
ServerName bbs.king.org
ServerAlias bbs.org
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin 185604832@qq.com
DocumentRoot "/var/www/blog"
ServerName blog.king.org
ServerAlias blog.org
ErrorLog "logs/blog-error_log"
CustomLog "logs/blog-access_log" common
</VirtualHost>
2.基于端口的虚拟主机
在httpd.conf中添加两行
Listen 8000
Listen 9000
<VirtualHost *:80>
ServerAdmin 185604832@qq.com
DocumentRoot "/var/www/web"
ServerName www.king.org
ServerAlias king.org
ErrorLog "logs/web-error_log"
CustomLog "logs/web-access_log" common
</VirtualHost>
<VirtualHost *:8000>
ServerAdmin 185604832@qq.com
DocumentRoot "/var/www/bbs"
ServerName bbs.king.org
ServerAlias bbs.org
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>
<VirtualHost *:9000>
ServerAdmin 185604832@qq.com
DocumentRoot "/var/www/blog"
ServerName blog.king.org
ServerAlias blog.org
ErrorLog "logs/blog-error_log"
CustomLog "logs/blog-access_log" common
</VirtualHost>
httpd -k graceful
netstat -tlunp|grep -E "8000|9000"
tcp 0 0 :::8000 :::* LISTEN 89128/httpd
tcp 0 0 :::9000 :::* LISTEN 89128/httpd
3.基于IP的虚拟主机
ifconfig eth0:0 192.168.1.118/24 up
<VirtualHost 192.168.1.115:80>
ServerAdmin 185604832@qq.com
DocumentRoot "/var/www/web"
ServerName 192.168.1.115
ServerAlias king.org
ErrorLog "logs/web-error_log"
CustomLog "logs/web-access_log" common
</VirtualHost>
<VirtualHost 192.168.1.118:80>
ServerAdmin 185604832@qq.com
DocumentRoot "/var/www/bbs"
ServerName 192.168.1.118
ServerAlias bbs.org
ErrorLog "logs/bbs-error_log"
CustomLog "logs/bbs-access_log" common
</VirtualHost>