一、基于IP
1. 假设服务器有个IP地址为192.168.1.10,使用ifconfig在同一个网络接口eth0上绑定3个IP:
[root@localhost root]# ifconfig eth0:2 192.168.1.12
[root@localhost root]# ifconfig eth0:3 192.168.1.13
2. 修改hosts文件,添加三个域名与之一一对应:
192.168.1.12 www.test2.com
192.168.1.13 www.test3.com
3. 建立虚拟主机存放网页的根目录,如在/www目录下建立test1、test2、test3文件夹,其中分别存放1.html、2.html、3.html
/www/test2/2.html
/www/test3/3.html
4. 在httpd.conf中将附加配置文件httpd-vhosts.conf包含进来,接着在httpd-vhosts.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
5. 大功告成,测试下每个虚拟主机,分别访问www.test1.com、www.test2.com、www.test3.com
二、基于主机名
1. 设置域名映射同一个IP,修改hosts:
192.168.1.10 www.test2.com
192.168.1.10 www.test3.com
2. 跟上面一样,建立虚拟主机存放网页的根目录
/www/test2/2.html
/www/test3/3.html
3. 在httpd.conf中将附加配置文件httpd-vhosts.conf包含进来,接着在httpd-vhosts.conf中写入如下配置:
下一步就是为你建立的每个虚拟主机设定
如果在现有的web服务器上增加虚拟主机,必须也为现存的主机建造一个
ServerName *
DocumentRoot /www/
ServerName www.test1.com
DocumentRoot /www/test1/
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
ServerName www.test2.com
DocumentRoot /www/test2/
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
ServerName www.test3.com
DocumentRoot /www/test3/
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
4. 大功告成,测试下每个虚拟主机,分别访问www.test1.com、www.test2.com、www.test3.com
三、基于端口
将原来的
Listen 80
改为
Listen 80
Listen 8080
2. 更改虚拟主机设置:
DocumentRoot /var/www/test1/
ServerName www.test1.com
DocumentRoot /var/www/test2
ServerName www.test2.com

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
