建立虚拟主机存放网页的根目录,3、虚拟主机的

作者: 操作系统  发布:2019-11-19

端口同是80端口。

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here
</VirtualHost>

复制代码 代码如下:

一、基于IP

Apache的虚构主机是风度翩翩种允许在长期以来台机械上布署多个例外站点的web服务器碰着的,正是iis相像可以创建多站点了,但是apache须求在编排状态操作,无法像windows iis直接点击几下就好了,下边笔者来给各位介绍配置格局。

<VirtualHost 172.20.30.40:80>
DocumentRoot /www/example1-80
ServerName www.example1.com
</VirtualHost>

复制代码 代码如下:

</VirtualHost>

复制代码

粗略的说,展开httpd.conf 在最终参与如下内容:

2、单域名多端口设置

/www/test1/1.html
/www/test2/2.html
/www/test3/3.html

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "g:/www"
<Directory "g:/www">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    #
    # for more information.
    #
    Options Indexes FollowSymLinks

"d:/AppServ/www2" 为你的站点贮存目录:重启apache2今后,你的虚构主机就安排好了,以后就可以透过127.0.0.2,和127.0.0.3跻身分化的站点了。

~~~~~~~~~~~
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL: >
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost *:81
NameVirtualHost *:82
NameVirtualHost *:83
NameVirtualHost *:84
NameVirtualHost *:85
NameVirtualHost *:86
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:81>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/www-nongye
ServerName www.dede.com
ErrorLog D:/AppServ/www/www-nongye/errornongye.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:82>
<Directory "D:/AppServ/www-chinaec" >
Options FollowSymLinks
#Deny from all
Allow from all
</Directory>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www-chinaec
ServerName www.dede.com
DirectoryIndex index.php index.html
ErrorLog D:/AppServ/www-chinaec/errornongjiale.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:83>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/www-05110
ServerName www.dede.com
ErrorLog D:/AppServ/www/www-05110/errornong05110.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:84>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/wordpress
ServerName www.dede.com
ErrorLog D:/AppServ/www/wordpress/errornongwordpress.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:85>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/magento
ServerName www.dede.com
ErrorLog D:/AppServ/www/magento/errormagento.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:86>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/magento1322
ServerName www.dede.com
ErrorLog D:/AppServ/www/magento1322/errormagento1322.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:88>
ServerAdmin jsw7001@hotmail.com
DocumentRoot D:/AppServ/www/www-nongjiale
ServerName www.dede.com
ErrorLog D:/AppServ/www/www-nongjiale/errornongjiale.log
CustomLog logs/dummy-host2.appservnetwork.com-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.x
DocumentRoot "C:/Apache2.2/docs/dummy-host2.x"
ServerName dummy-host2.x
ErrorLog "logs/dummy-host2.x-error.log"
CustomLog "logs/dummy-host2.x-access.log" common
</VirtualHost>

  DocumentRoot /www/ 

复制代码

4、然后相应的安排好各种目录属性,上面是三个索引属性的第一名配置:
<Directory "d:/AppServ/www2">
    Options Indexes FollowSymLinks Multiviews
    AllowOverride All
    Order Allow,Deny
    Allow from all
</Directory>

给二个规范配置吧

<VirtualHost 192.168.1.12:80>
  ServerName www.test1.com
  DocumentRoot /www/test2/
  <Directory "/www/test2">
     Options Indexes FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow From All
   </Directory>
</VirtualHost>

IP地址1:192.168.2.2

<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here
</VirtualHost>

DocumentRoot "/srv/www/htdocs"
#
# Configure the DocumentRoot
#
<Directory "/srv/www/htdocs">
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
#
# for more information.
Options None
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
AllowOverride None
# Controls who can get stuff from this server.
Order allow,deny
Allow from all
</Directory>

    Order allow,deny

第三种多IP同端口。

<VirtualHost 172.20.30.40:8080>
ServerName www.example2.org
DocumentRoot /www/otherdomain-8080
</VirtualHost>

3、多域名多端口设置

192.168.1.11   www.test1.com
192.168.1.12   www.test2.com
192.168.1.13   www.test3.com

 代码如下

NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080

<Directory "/srv/www/htdocs/btc">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory "/srv/www/htdocs/bbs">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory "/srv/www/htdocs/">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
NameVirtualHost   *:80
NameVirtualHost   *:81
<VirtualHost *:80>
  DirectoryIndex  index.html index.php
  ServerName   "www.abc.com "
  DocumentRoot   "/srv/www/htdocs/" 
  </VirtualHost>
<VirtualHost *:80>
  DirectoryIndex  index.html index.php
  ServerName   "www.btc.com "
  DocumentRoot   "/srv/www/htdocs/btc" 
  </VirtualHost>
<VirtualHost *:81>
  DirectoryIndex   index.php
    ServerName   "www.abc.com:81 "
  DocumentRoot   "/srv/www/htdocs/bbs/" 
  </VirtualHost>

 

 代码如下

NameVirtualHost 172.20.30.40

粗体部分是关键点。
(3)发布站点
# ln -s /etc/apache2/sites-available/default-me /etc/apache2/sites-enabled/001-default
(4)重启服务 #/etc/init.d/apache2 restart
(5)测试
若果能够寻常访谈就表明配置不错了。

 

<VirtualHost 192.168.2.2:80>
    ServerAdmin admin@myxzy.com
    ServerName www.111cn.net
    DocumentRoot "g:/www1"
     <Directory "g:/www1">
     Options FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>  
</VirtualHost>
<VirtualHost 192.168.2.2:80>
    ServerAdmin admin@myxzy.com
    ServerName www.111cn.net
    DocumentRoot "g:/www2"
   <Directory "g:/www2">
     Options FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>      
</VirtualHost>

# This is the other address
NameVirtualHost 172.20.30.50

特意表明,apache的布置暗许都在安装目录下的conf目录里面
或者是/etc/apache2
只是分明要在乎,listen.conf文件中端口监听是或不是开启
如下图,表示已经拉开80端口监听
直接暗许校正default-server.conf

  ServerName www.test1.com

IP地址2:192.168.1.68

打开:hosts文件

<VirtualHost *:8000 >
    ServerAdmin webmaster@localhost
    DocumentRoot /wwwroot
    <Directory / >
Options FollowSymLinks
AllowOverride None
    </Directory>
    <Directory /wwwroot/ >
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
    </Directory>
    ErrorLog /var/log/apache2/error.log
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
    CustomLog /var/log/apache2/access.log combined
</VirtualHost>

9159金沙官网 1

第三种:多IP同端口(独立IP的杜撰空间卡塔尔国

重启apache2以往,你的虚构主机就布局好了,今后就足以经过127.0.0.1和127.0.0.2,127.0.0.3进去分歧的站点了。

您或者感兴趣的稿子:

  • Linux下查看端口占用进度号,程序名的点子
  • Linux/window下什么查看有个别端口被哪些程序/进度占用
  • Windwos下行使winscp和批管理达成通过SSH端口上传文件到Linux服务器上
  • Linux利用nc命令监察和控制服务器端口的办法
  • Linux下用netstat查看互联网状态、端口状态
  • 什么缓和windows系统和linux系统中端口被占用的题材
  • linux下mysql开启远程访问权限 防火墙开放3306端口
  • 应用iptables来布局linux制止全体端口登录和盛放钦命端口的点子
  • linux下防火墙开启有些端口号及防火墙常用命令使用(详细明白)
  • 详整Linux 查看服务器开放的端口号

    Options Indexes FollowSymLinks

第黄金时代种:单IP区别端口

==========================================================================

一贯暗中认可
1、单域名单端口设置
如:www.abc.com 默认用80访问

9159金沙官网 2

大约在50几行有个Listen 80,在底下增加8080端口。

<VirtualHost 172.20.30.50>
DocumentRoot /www/example1
ServerName www.example1.com
# Other directives here …
</VirtualHost>
IXDBA.NET社区论坛

复制代码 代码如下:

9159金沙官网 3

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80

<VirtualHost 172.20.30.50:80>
DocumentRoot /www/example2-80
ServerName www.example1.org
</VirtualHost>

1、单域名单端口设置 如:www.abc.com 默认用80访问

 

 代码如下

(5)在差异的端口上运维区别的站点(基于多端口的服务器上陈设基于域名的虚构主机):
Listen 80
Listen 8080

<Directory "/srv/www/htdocs/bbs">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
<Directory "/srv/www/htdocs/">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
NameVirtualHost   *:80
NameVirtualHost   *:81
<VirtualHost *:80>
  DirectoryIndex  index.html index.php
  ServerName   "www.abc.com "
  DocumentRoot   "/srv/www/htdocs/" 
  </VirtualHost>
<VirtualHost *:81>
  DirectoryIndex   index.php
    ServerName   "www.abc.com:81 "
  DocumentRoot   "/srv/www/htdocs/bbs/" 
  </VirtualHost>

  ServerName *

上边多站点扶持的话,修正httpd.conf的第187~264行(不一致的httpd.conf大概大有不相同卡塔 尔(阿拉伯语:قطر‎,相当于在ServerAdmin和ServerName这里,大多数是注释。下边是非常重要修改之处。

<VirtualHost 127.0.0.3:80>
    DocumentRoot d:/AppServ/www3
    ServerName 127.0.0.3:80
</VirtualHost>...

其生机勃勃布局最好轻松 设置好了,之后,私下认可已经能够运用了,只是要把它改善成你须要的域名及拜望路线罢了。

 

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

2、修改httpd.conf.

特地表明,apache的安插暗中同意都在装置目录下的conf目录里面
或者是/etc/apache2
不过应当要注意,listen.conf文件中端口监听是不是开启
平日来讲图,表示曾经开启80端口监听

/www/test1/1.html
/www/test2/2.html
/www/test3/3.html

其两种同IP分裂域名和根目录(域名的话改正本地host演示卡塔 尔(阿拉伯语:قطر‎。

<VirtualHost 172.20.30.40:8080>
DocumentRoot /www/example1-8080
ServerName www.example1.com
</VirtualHost>

复制代码 代码如下:

  将原来的

其二种:域名绑定根目录的主意(共享IP的捏造空间卡塔尔

<Directory "d:/AppServ/www3">
    Options Indexes FollowSymLinks Multiviews
    AllowOverride All
    Order Allow,Deny
    Allow from all
</Directory>

亟待在乎的难题是,多端口监听,应当要注意listen.conf文件,是不是张开了相应端口。

  DocumentRoot /www/test3/

<VirtualHost 192.168.1.68:80>
    ServerAdmin admin@myxzy.com
    ServerName localhost:80
    DocumentRoot "g:/www1"
     <Directory "g:/www1">
     Options FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>  
</VirtualHost>
<VirtualHost 192.168.2.2:80>
    ServerAdmin admin@myxzy.com
    ServerName localhost:80
    DocumentRoot "g:/www2"
   <Directory "g:/www2">
     Options FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>      
</VirtualHost>

<Directory />
Options FollowSymLinks
AllowOverride None
### Order deny,allow
### Deny from all
Order allow,deny
Allow from all
Satisfy all
</Directory>

复制代码 代码如下:

 2. 跟下面同样,创立设想主机存放网页的根目录

# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

(3)单个IP地址的服务器上根据域名的虚构主机配置:
# Ensure that Apache listens on port 80
Listen 80

暗许情况下,linux上apache使用的
暗许文书档案目录是:/var/www
暗中同意端口是:80
如若想昭示温馨的二个系统财富目录,能够动用上面包车型地铁措施,试行如下命令:
(1)增添监听端口 #cd /etc/apache2
#vim ports.conf
文本增添:
NameVirtualHost *:8000
Listen 8000
(2)配置设想目录
#cd /etc/apache2/sites-available
#cp default default-me
#vim default-me
文本内容如下:

 3. 创设设想主机寄放网页的根目录,如在/www目录下建设构造test1、test2、test3文件夹,当中分别寄放1.html、2.html、3.html

Listen 80
Listen 8080<VirtualHost *:80>
    ServerAdmin admin@myxzy.com
    ServerName localhost:80
    DocumentRoot "g:/www1"
     <Directory "g:/www1">
     Options  Indexes FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>  
</VirtualHost>
<VirtualHost *:8080>
    ServerAdmin admin@myxzy.com
    ServerName localhost:8080 
    DocumentRoot "g:/www2"
   <Directory "g:/www2">
     Options Indexes FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>      
</VirtualHost>

<VirtualHost 172.20.30.40>
DocumentRoot /www/example3
ServerName www.example3.net
</VirtualHost>

 

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
    AllowOverride All
    Require all denied
</Directory>

3、设想主机的布局
(1)基于IP地址的设想主机配置
Listen 80
<VirtualHost 172.20.30.40>
DocumentRoot /www/example1
ServerName www.example1.com
</VirtualHost>
<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example2.org
</VirtualHost>

</VirtualHost>

复制代码

(6)基于域名和基于IP的混合虚构主机的安顿:
Listen 80

<VirtualHost 192.168.1.11:80>
  ServerName www.test1.com
  DocumentRoot /www/test1/
  <Directory "/www/test1">
     Options Indexes FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow From All
   </Directory>
</VirtualHost>

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
ServerAdmin admin@example.com

<VirtualHost 172.20.30.40>
DocumentRoot /www/example1
ServerName www.example1.com
</VirtualHost>

    AllowOverride None

事例分别通过80和8080拜谒分歧的根目录。

运行:C:WINDOWSsystem32driversetc

三、基于端口

 代码如下

<VirtualHost 172.20.30.40:80>
ServerName www.example1.com
DocumentRoot /www/domain-80
</VirtualHost>

<VirtualHost 192.168.1.10:80>
    DocumentRoot /var/www/test1/
    ServerName www.test1.com
</VirtualHost>

Apache的着力配置文件名是”httpd.conf”,其所寄存的门径在Apache目录下的conf文件夹下。修正它只必要运用记事本(建议使用其余编辑器,带行数的这种,方便改革卡塔尔,生效的话只需求保留httpd.conf,重启apache即可。

1、校勘域名访问方式:

</VirtualHost> 

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

增加域名指向。

 1. 设置域名映射同八个IP,改进hosts:

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

首先,我们都领会,全体以127抢先的ip地址都应该针对本机,并不仅127.0.0.1,那一点我们能够实施。
那样一来,也正是说本机有丰裕多的ip地址供您来开设设想主机了。

 3. 在httpd.conf元帅附加配置文件httpd-vhosts.conf包蕴进来,接着在httpd-vhosts.conf中写入如下配置:

最平凡的差不离有3种格局。

<VirtualHost 172.20.30.40:8080>
ServerName www.example1.com
DocumentRoot /www/domain-8080
</VirtualHost>

  ServerName www.test3.com

留意:如果是服务器请备份httpd.conf后再更正文件。

<Directory "d:/AppServ/www2">
    Options Indexes FollowSymLinks Multiviews
    AllowOverride All
    Order Allow,Deny
    Allow from all
</Directory>

<VirtualHost 192.168.1.10:8080>
    DocumentRoot /var/www/test2
    ServerName www.test2.com
</VirtualHost>

复制代码

<VirtualHost 172.20.30.50:8080>
DocumentRoot /www/example2-8080
ServerName www.example2.org
</VirtualHost>

  1. 纠正虚构主机设置:

第大器晚成种日常是测量检验情况,究竟加了端口,怎么样绑定域名,访问的时候域名后边也需加端口。

(2) 基于IP和多端口的虚构主机配置
Listen 172.20.30.40:80
Listen 172.20.30.40:8080
Listen 172.20.30.50:80
Listen 172.20.30.50:8080

    Order allow,deny

# Listen for virtual host requests on all IP addresses
9159金沙官网 ,NameVirtualHost *:80

  DocumentRoot /www/test1/

<VirtualHost 127.0.0.2:80>
    DocumentRoot d:/AppServ/www2
    ServerName 127.0.0.2:80
</VirtualHost>

1.  改变配置文件

(4)在多个IP地址的服务器上布署基于域名的设想主机:
Listen 80

    AllowOverride None

3、虚构主机配置段:在httpd.conf 最终加上
<VirtualHost 127.0.0.2:80>
    DocumentRoot d:/AppServ/www2
    ServerName 127.0.0.2:80
</VirtualHost>

  为了采纳基于域名的设想主机,必需钦定服务器IP地址(和也许的端口卡塔 尔(阿拉伯语:قطر‎来使主机选拔需要。能够用NameVirtualHost指令来进展安排。 若是服务器上具有的IP地址都会用到, 你能够用*作为NameVirtualHost的参数。在NameVirtualHost指令中指明IP地址并不会使服务器自动侦听那三个IP地址。 这里设定的IP地址必需对应服务器上的二个互连网接口。

<VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here …
</VirtualHost>

    Allow from all

# This is the "main" server running on 172.20.30.40
ServerName server.domain.com
DocumentRoot /www/mainserver

  ServerName www.test2.com

下边为详细表明深入分析:

    Allow from all

在大家设置APACHE的时候平时暗许的apache的配备是独有多个网址,那样切换起来特不便于。其实这些难题很好化解,正是把本机的apache配置成为虚构服务器。不过,网络海南大学学部分科目标是教用 apache如何配置基于域名的设想主机的,而在本机调节和测量试验网址的时候,常常都以用本地ip(127.0.0.1 或 localhost卡塔尔直接待上访谈,未有用到域名。所以得把apache配置成为基于ip地址的虚构主机。

9159金沙官网 4

废话少说,步向典型的计划专门的学业,上边是apache的httpd.conf里相关陈设部分( httpd.conf 位于 Apache2.2conf ):
1、Listen部分,必得平昔内定端口,不钦命ip地址,配置应写为:
Listen 80
2、不用像基于域名的虚构主机那样写“NameVirtualHost”。

  下一步就是为您建设构造的每一个设想主机设定<VirtualHost>配置块,<VirtualHost>的参数与NameVirtualHost指令的参数是大器晚成致的。各种<VirtualHost>定义块中,起码都会有一个ServerName指令来钦点伺服哪个主机和二个DocumentRoot指令来注解这几个主机的源委存在于文件系统的如哪儿方。

<VirtualHost 172.20.30.40>
DocumentRoot /www/example2
ServerName www.example2.org
</VirtualHost>

9159金沙官网 5

要不会并发无权访谈难点。

<VirtualHost 192.168.1.13:80>
  ServerName www.test1.com
  DocumentRoot /www/test3/
  <Directory "/www/test3">
     Options Indexes FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow From All
   </Directory>
</VirtualHost>

配备生效前提,必得纠正跟目录为:

    Options Indexes FollowSymLinks

<VirtualHost 172.20.30.40:80>
ServerName www.example2.org
DocumentRoot /www/otherdomain-80
</VirtualHost>

    Allow from all

    AllowOverride None

  </Directory>

    Order allow,deny

 

  </Directory>

NameVirtualHost *:80
<VirtualHost *:80>  

9159金沙官网 6

 4. 马到功成,测量试验下各类设想主机,分别探望www.test1.com、www.test2.com、www.test3.com

192.168.1.10  www.test1.com
192.168.1.10  www.test2.com
192.168.1.10  www.test3.com

  <Directory "/www/test2">

  <Directory "/www/test3">

  DocumentRoot /www/test2/

<VirtualHost *:80>

 2. 改变hosts文件,增添五个域名与之后生可畏风姿罗曼蒂克对应:

[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

    Listen 80
      改为
      Listen 80
      Listen 8080

    Options Indexes FollowSymLinks

<VirtualHost *:80>

 5. 马到功成,测量试验下每一种虚构主机,分别探访www.test1.com、www.test2.com、www.test3.com

<VirtualHost *:80>

  假若在现成的web服务器上扩充虚构主机,必得也为现成的主机建造三个<VirtualHost>定义块。此中ServerName和DocumentRoot所满含的内容应该与全局的保持意气风发致,且要放在配置文件的最前面,扮演默许主机的角色。

二、基于主机名

 4. 在httpd.conf中校附加配置文件httpd-vhosts.conf饱含进来,接着在httpd-vhosts.conf中写入如下配置:

  <Directory "/www/test1">

  </Directory>

 

 1. 万风姿浪漫服务器有个IP地址为192.168.1.10,使用ifconfig在同一个网络接口eth0上绑定3个IP:

</VirtualHost>

本文由9159.com发布于操作系统,转载请注明出处:建立虚拟主机存放网页的根目录,3、虚拟主机的

关键词: