当前位置 主页 > 服务器问题 > Linux/apache问题 >

    Apache服务器一个IP多个站点的配置方法示例

    栏目:Linux/apache问题 时间:2019-10-14 12:17

    在日常的网站发布中很多情况下都无法做到一个IP对应一个站点,在IP4的情况下IP的资源是相对有限的。然而作为最流行的Apache自然也考虑到这种情况,那么接下来看看apache服务器怎么配置一个IP多个站点。

    在httpd.conf中找到 "# Virtual hosts",并添加如下行
    复制代码 代码如下:
    ServerName 你的域名
    HostNameLookups off

    例子  

    NameVirtualHost 192.168.1.104
    
    <VirtualHost 192.168.1.104>
        ServerName www.php.com
        ServerAdmin test@gmail.com
        DocumentRoot /data/www1/
        DirectoryIndex index.php index.html index.htm index.shtml
        Errorlog /usr/local/apache2/logs/wwwError_log
        Loglevel warn
        HostNameLookups off
        <Directory /data/www1/>
         AllowOverride None
         Order allow,deny
         Allow from all
        </Directory>
    </VirtualHost>
    
    <VirtualHost 192.168.1.104>
        ServerName bbs.php.com
        ServerAdmin test@gmail.com
        DocumentRoot /data/www2/
        DirectoryIndex index.php index.html index.htm index.shtml
        Errorlog /usr/local/apache2/logs/bbsError_log
        Loglevel warn
        HostNameLookups off
        <Directory /data/www2/>
         AllowOverride None
         Order allow,deny
         Allow from all
        </Directory>
    </VirtualHost>
    

    上述的例子IP都是192.168.1.104,域名分别是www.php.com和bbs.php.com。因而可知apahce是通过ServerName来识别同一个IP下的不同站点的。

      在实际应用中你只需要将IP192.168.1.104、域名www.php.com和bbs.php.com分别改成你的IP和域名即可。