apache configures virtual host based on ip

王林
Release: 2020-06-29 18:01:02
forward
2659 people have browsed it

apache configures virtual host based on ip

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行
Copy after login
Include conf/extra/httpd-vhosts.conf //去掉#的意思是从httpd-vhosts.conf这个文件导入虚拟主机配置
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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    
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!