LAMP中添加多虚拟主机

在/etc/apache2/sites-available中默认有个default文件,其中的大致配置如下:

  1. <VirtualHost *:80>  
  2.     ServerAdmin xujie19841206@hotmail.com  
  3.     ServerName localhost  
  4.     DocumentRoot /home/xujie/www  
  5.     <Directory />  
  6.         Options indexes FollowSymLinks  
  7.         AllowOverride All  
  8.     </Directory>  
  9.     <Directory /home/xujie/www/>  
  10.         Options Indexes FollowSymLinks MultiViews  
  11.         AllowOverride All  
  12.         Order allow,deny  
  13.         allow from all  
  14.     </Directory>  
  15.     ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/  
  16.     <Directory "/usr/lib/cgi-bin">  
  17.         AllowOverride None  
  18.         Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch  
  19.         Order allow,deny  
  20.         Allow from all  
  21.     </Directory>  
  22.     ErrorLog /var/log/apache2/error.log  
  23.     # Possible values include: debug, info, notice, warn, error, crit,  
  24.     # alert, emerg.  
  25.     LogLevel warn  
  26.     CustomLog /var/log/apache2/access.log combined  
  27.     Alias /doc/ "/usr/share/doc/"  
  28.     <Directory "/usr/share/doc/">  
  29.         Options Indexes MultiViews FollowSymLinks  
  30.         AllowOverride None  
  31.         Order deny,allow  
  32.         Deny from all  
  33.         Allow from 127.0.0.0/255.0.0.0 ::1/128  
  34.     </Directory>  
  35. </VirtualHost>  

当你输入http://localhost时,服务器会自动解析到/home/xujie/www文件夹下。找到index.PHP,然而如果你想再添加一个虚拟主机,在本地添加。

每个站点的IP地址相同,但域名不同,则称为基于名字或主机名的虚拟主机。

如果你想再次建立一个www.drug.com.cn目录,然后在/etc/apache2/sites-available/ 目录中建立一个文件,名为drug,然后通过sudo gedit drug,

添加

<VirtualHost 127.0.0.1>
    ServerName www.drug.com.cn
    ServerAdmin abc@abc.com
    DocumentRoot "/home/xujie/www/drug"
    ErrorLog "/var/log/apache2/drug_errors.log"
</VirtualHost>

到这里并没有完成,需要修改host文件,编辑/etc/hosts,然后添加127.0.0.1    www.drug.com.cn这里行,服务器重启,就可以让www.drug.com.cn自动解析到本地的/home/xujie/www/drug目录了。

 

转载至: http://blog.csdn.net/lqk1985/article/details/5297364;

posted @ 2017-06-26 13:15  PHP-小菜  阅读(268)  评论(0编辑  收藏  举报