Configure Apache Virtual host to run multiple Web sites on a single server
Apache Virtual host implementations are available in three ways:
1. Through different IP addresses
2, through the different domain name
3, through a different port number
three need to open the virtual host function :
[Email protected] ~]# vim/etc/httpd/conf/httpd.conf
Change:
#NameVirtualHost *:80
For:
Namevirtualhost *:80
Method 1: Resolve different domain names with different IP addresses
Add IP to the server (another domain name resolution)
[Email protected] ~]# ifconfig eth0:1 192.168.1.65
[Email protected] ~]# Mkdir/var/www/html/bbs
[Email protected] ~]# echo "bbs.xuegod.cn" >/var/www/html/bbs/index.html
[Email protected] ~]# echo "www.xuegod.cn" >/var/www/html/index.html
Modify Httpd.conf
[Email protected] ~]# vim/etc/httpd/conf/httpd.conf
<virtualhost 192.168.1.63:80>
ServerAdmin [email protected]
documentroot/var/www/html/
ServerName www.xuegod.cn
Errorlog Logs/www.xuegod.cn-error_log
Customlog Logs/www.xuegod.cn-access_log Common
</VirtualHost>
<virtualhost 192.168.1.65:80>
ServerAdmin [email protected]
documentroot/var/www/html/bbs/
ServerName bbs.xuegod.cn
Errorlog Logs/bbs.xuegod.cn-error_log
Customlog Logs/bbs.xuegod.cn-access_log Common
</VirtualHost>
Method 2: Configure the virtual host with a different domain name
#vim httpd.conf
Change: #NameVirtualHost *:80
Namevirtualhost 192.168.1.63
<virtualhost www.xuegod63.cn>
ServerAdmin [email protected]
documentroot/var/www/html/
ServerName www.xuegod.cn
Errorlog Logs/www.xuegod.cn-error_log
Customlog Logs/www.xuegod.cn-access_log Common
</VirtualHost>
<virtualhost bbs.xuegod63.cn>
ServerAdmin [email protected]
documentroot/var/www/html/bbs/
ServerName bbs.xuegod.cn
Errorlog Logs/bbs.xuegod.cn-error_log
Customlog Logs/bbs.xuegod.cn-access_log Common
</VirtualHost>
[Email protected] ~]# vim/etc/hosts
192.168.1.63 www.xuegod63.cn
192.168.1.63 bbs.xuegod63.cn
Restart Service
Service httpd Restart
Verify:
http://www.xuegod63.cn
http://bbs.xuegod63.cn
Method 3: Configure the virtual host with different ports
[Email protected] conf]# vim/etc/httpd/conf/httpd.conf
Change:
Listen 80
For:
Listen 80
Listen 8080
#更改为你要添加的端口
Create 2 more Virtual hosts
<virtualhost *:80>
ServerAdmin [email protected]
documentroot/var/www/html/
ServerName www.xuegod.cn
Errorlog Logs/www.xuegod.cn-error_log
Customlog Logs/www.xuegod.cn-access_log Common
</VirtualHost>
<virtualhost *:8080>
ServerAdmin [email protected]
documentroot/var/www/html/bbs/
ServerName bbs.xuegod.cn
Errorlog Logs/bbs.xuegod.cn-error_log
Customlog Logs/bbs.xuegod.cn-access_log Common
</VirtualHost>
Restart Service
Service httpd Restart
Verify:
http://192.168.1.63
http://192.168.1.63:8080
This article is from the "Innocence" blog, be sure to keep this source http://innocence.blog.51cto.com/4313888/1963374
Configure Apache Virtual host to run multiple Web sites on a single server