apache單ip多域名多目錄配置

本身的vps上放了別人的網站,那怎麼樣讓本身的網站和別人的網站能同時被訪問呢?須要使用apache的虛擬主機配置。html

 

配置httpd.conf文件apache

 

好比原來是這種只是指向一個目錄的配置服務器

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>

把這段話變成ide

<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 也須要如上再配置一遍。ui

相關文章
相關標籤/搜索