zoukankan      html  css  js  c++  java
  • apache单ip多域名多目录配置

    自己的vps上放了别人的网站,那怎么样让自己的网站和别人的网站能同时被访问呢?需要使用apache的虚拟主机配置。

    配置httpd.conf文件

    比如原来是这种只是指向一个目录的配置

    DocumentRoot "/opt/lampp/htdocs/ppe112"
    <Directory "/opt/lampp/htdocs/ppe112">
        #
        # 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/trunk/mod/core.html#options
        # for more information.
        #
        #Options Indexes FollowSymLinks
        # XAMPP
        Options Indexes FollowSymLinks ExecCGI Includes
    
        #
        # 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
        # since XAMPP 1.4:
        AllowOverride All
    
        #
        # Controls who can get stuff from this server.
        #
        Require all granted
    </Directory>

    把这段话变成

    <VirtualHost 198.199.107.XXX>       #这里填主机的ip地址
         ServerName www.AAA.com
         DocumentRoot "/opt/lampp/htdocs/AAA"
        <Directory "/opt/lampp/htdocs/AAA">
            #
            # 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/trunk/mod/core.html#options
            # for more information.
            #
            #Options Indexes FollowSymLinks
            # XAMPP
            Options Indexes FollowSymLinks ExecCGI Includes
    
            #
            # 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
            # since XAMPP 1.4:
            AllowOverride All
    
            #
            # Controls who can get stuff from this server.
            #
            Require all granted
        </Directory>
    </VirtualHost>
    
    <VirtualHost 198.199.107.XXX>       #这里填主机的ip地址
         ServerName www.BBB.com
         DocumentRoot "/opt/lampp/htdocs/BBB"
        <Directory "/opt/lampp/htdocs/BBB">
            #
            # 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/trunk/mod/core.html#options
            # for more information.
            #
            #Options Indexes FollowSymLinks
            # XAMPP
            Options Indexes FollowSymLinks ExecCGI Includes
    
            #
            # 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
            # since XAMPP 1.4:
            AllowOverride All
    
            #
            # Controls who can get stuff from this server.
            #
            Require all granted
        </Directory>
    </VirtualHost>

    这样就实现了AAA网站和BBB网站同时在服务器上共存,外部两个域名指向同一个ip,内部解析到不同服务器目录的操作。

    PS:这里这里只能正常访问www.AAA.com  www.BBB.com这两个,如果要直接访问AAA.com  BBB.com 也需要如上再配置一遍。

  • 相关阅读:
    一些精简的小技巧
    POJ题目分类(转)
    【慢慢学算法】:连通图
    【菜鸟做水题】: 杭电1004
    杭电ACM试题分类,一步一个脚印!(转)
    【慢慢学Android】:获得当前时间
    【慢慢学算法】:小白鼠排队
    【慢慢学Android】:12.Notification示例
    【慢慢学Android】:13.打电话代码
    “/”应用程序中的服务器错误。
  • 原文地址:https://www.cnblogs.com/hongchenok/p/3569945.html
Copyright © 2011-2022 走看看