手机游戏
经典单机
角色扮演
休闲益智
动作冒险
射击枪战
赛车竞速
模拟经营
解密闯关
策略战争
手机软件
时尚购物
体育运动
资讯阅读
教育学习
摄影摄像
生活服务
效率办公
聊天社交
视频盒子
其它软件
新闻资讯
游戏攻略
软件教程
游戏问答
软件资讯
软件技术
叨叨念念
网站技术
技术问答
软件教程
资源资料
原创作品
代码学习
网页设计
网络技术
合集
合集
游戏合集
软件合集
资讯合集
视频合集
首页 > 网站技术 > 网站技术

Apache搭建多个站点

作者:星知苑 时间:2012-12-04 09:34:21

如何用Apache搭建的网站系统上运行多个站点呢?最平常的大概有3种方法。

第一种:单IP不同端口

第二种:多IP同端口(独立IP的虚拟空间)

第三种:域名绑定根目录的方式(共享IP的虚拟空间)

 

下面简单来说这3种方法是如何配置的。

Apache的核心配置文件名是”httpd.conf”,其所存放的路径在Apache目录下的conf文件夹下。[break]修改它只需要使用记事本(建议使用其他编辑器,带行数的那种,方便修改),生效的话只需要保存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
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # 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 keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # 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> 
    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.a.com 
    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.b.com  
    DocumentRoot "g:/www2" 
   <Directory "g:/www2"> 
     Options FollowSymLinks 
     AllowOverride All 
     Require all granted 
   </Directory>       
</VirtualHost>

点击查看原图

 

良心推荐

爆率最高的免费捕鱼游戏
  • 火山捕鱼官方下载
  • 捕鱼炸翻天官网下载
  • 捕鱼大世界无限金币版
  • 捕鱼欢乐颂官方下载最新版本
  • 暖风捕鱼日下载
  • 深海街机捕鱼下载
这里是捕鱼能手的世界超多的不同的鱼类让你捕到手酸都是可以的,精彩火爆的真实玩家线上的对抗看谁的手速更快更加的可以驾驭各种不同的大炮,有的还有多种武器可以进行装备也有丰富好看的皮肤在这里让玩家可以进行更换,还有属性各种加成,爆率是超级的高,想不要金币都是很难的那种哦。

相关资讯