Tagged Tags:

Apache的虚拟主机是一种允许在平等台机械上安顿三个例外站点的web服务器情形的,正是iis同样能够创设多站点了,不过apache要求在编写状态操作,不可能像windows
iis直接点击几下就好了,下边笔者来给诸位介绍配置情势。

最平凡的大致有3种方法。

先是种:单IP不相同端口

其次种:多IP同端口(独立IP的设想空间)

其二种:域名绑定根目录的措施(分享IP的杜撰空间)

Apache的基本配置文件名是”httpd.conf”,其所寄存的门道在Apache目录下的conf文件夹下。修改它只须求动用记事本(提议采纳任何编辑器,带行数的这种,方便修改),生效的话只要求保留httpd.conf,重启apache即可。

下边多站点协助的话,修改httpd.conf的第187~264行(差异的httpd.conf恐怕有异样),也正是在ServerAdmin和ServerName这里,大多数是注释。下边是重要修改的地方。

专注:即使是服务器请备份httpd.conf后再修改文件。

 代码如下

复制代码

# ‘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.
#

#
# 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

#
# 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

#
# 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>

#
# 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.
#

#
# 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
    #多IP同端口(亚搏app官方网站独立IP的杜撰空间)。
多IP同端口(亚搏app官方网站独立IP的杜撰空间)。    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess
files.
    # It can be “All”, “None”, or any combination of the
key多IP同端口(亚搏app官方网站独立IP的杜撰空间)。words:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

多IP同端口(亚搏app官方网站独立IP的杜撰空间)。    #
多IP同端口(亚搏app官方网站独立IP的杜撰空间)。    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

第一种一般是测量试验境况,毕竟加了端口,怎么着绑定域名,访谈的时候域名后边也需加端口。

事例分别通过80和8080拜望差异的根目录。

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

 代码如下

复制代码

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>
多IP同端口(亚搏app官方网站独立IP的杜撰空间)。    ServerAdmin admin@myxzy.com
    ServerName localhost:8080 
    DocumentRoot “g:/www2”
   <Directory “g:/www2”>
     Options Indexes FollowSymLinks
     AllowOverride All
     Require all granted
   </Directory>      
</VirtualHost>

其次种多IP同端口。

IP地址1:192.168.2.2

IP地址2:192.168.1.68

端口同是80端口。

 代码如下

复制代码

<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>

其二种同IP差别域名和根目录(域名的话修改本地host演示)。

 代码如下

复制代码

<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>

发表评论

电子邮件地址不会被公开。 必填项已用*标注