apache一個IP多個站點的配置方法


  在日常的網站發布中很多情況下都無法做到一個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和域名即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM