First we use Notepad to open the httpd.conf file, which is in the apache directory, such as: D:\AppServ\Apache2.2\conf, and modify the following two places:
(Recommended learning:apache from entry to proficiency)
LoadModule vhost_alias_module modules/mod_vhost_alias.so //去掉前面的#,意思是启用apache的虚拟主机功能,第203行
Include conf/extra/httpd-vhosts.conf //去掉#的意思是从httpd-vhosts.conf这个文件导入虚拟主机配置
After configuring the virtual host, you cannot use localhost to access it. You only need to change the ServerName of the httpd.conf file to localhost:80 Just comment out that line.
Based on IP
1. Assume that the server has an IP address of 192.168.1.10. Use ifconfig to bind 3 IPs on the same network interface eth0:
[root@localhost root]# ifconfig eth0:1 192.168.1.11 [root@localhost root]# ifconfig eth0:2 192.168.1.12 [root@localhost root]# ifconfig eth0:3 192.168.1.13
2. Modify the hosts file and add three domain names corresponding to one of them:
192.168.1.11 www.test1.com 192.168.1.12 www.test2.com 192.168.1.13 www.test3.com
3. Establish the root directory where the virtual host stores web pages, such as test1, test2, test3 folder, which stores 1.html, 2.html, and 3.html
/www/test1/1.html /www/test2/2.html /www/test3/3.html
4. Include the additional configuration file httpd-vhosts.conf in httpd.conf, and then in httpd-vhosts. Write the following configuration in conf:
ServerName www.test1.com DocumentRoot /www/test1/ Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All ServerName www.test1.com DocumentRoot /www/test2/ Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All ServerName www.test1.com DocumentRoot /www/test3/ Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow From All
Completed, now test each virtual host and visit www.test1.com, www.test2.com, www.test3.com respectively.
The above is the detailed content of apache configures virtual host based on ip. For more information, please follow other related articles on the PHP Chinese website!