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


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

在httpd.conf中找到 "# Virtual hosts",并添加如下行

复制代码 代码如下:

ServerName 你的域名
HostNameLookups off


例子  

?

?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
NameVirtualHost 192.168.1.104
?
<VirtualHost 192.168.1.104>
????ServerName php
????ServerAdmin test@gmail
????DocumentRoot /data/www1/
????DirectoryIndex index.php index index 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
????ServerAdmin test@gmail
????DocumentRoot /data/www2/
????DirectoryIndex index.php index index 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,域名分别是php和bbs.php。因而可知apahce是通过ServerName来识别同一个IP下的不同站点的。

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


上一篇:解决PHPstudy Apache无法启动的问题【亲测有效】

下一篇:phpstudy隐藏index.php的方法


Copyright © 2002-2019 测速网 https://www.inhv.cn/ 皖ICP备2023010105号 城市 地区 街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!
热门搜索