CentOS下Apache搭建虚拟主机的几种方式

Apache 是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中

基于域名的虚拟机

# cd /etc/httpd/conf.d/
# vim vhost.conf
NameVirtualHost 192.168.1.100
<VirtualHost 192.168.1.100>
DocumentRoot /data/web/test
ServerName www.test.com
ServerAlias  test.com   #绑定多个域名用空格隔开
DirectoryIndex index.php index.html   #设置默认访问页面
ErrorLog logs/www.test.com-error_log
CustomLog logs/www.test.com-access_log common
</VirtualHost>
<VirtualHost 192.168.1.100>
DocumentRoot /data/web/test2
ServerName www.test2.com
ServerAlias  test2.com   #绑定多个域名用空格隔开
DirectoryIndex index.php index.html   #设置默认访问页面
ErrorLog logs/www.test2.com-error_log
CustomLog logs/www.test2.com-access_log common
</VirtualHost>

 基于IP的虚拟主机

# ifconfig eth0:0 192.168.100.20                //设置另一个IP
# vim /etc/httpd/conf.d/vhost.conf
#NameVirtualHost *:80                        //不需要这行
<VirtualHost 192.168.10.10:80>
DocumentRoot /data/web/linuxidc
ServerName 192.168.100.10
ErrorLog logs/192.168.100.10-error_log
CustomLog logs/192.168.100.10-access_log common
</VirtualHost>
<VirtualHost 192.168.100.20:80>
DocumentRoot /data/web/linuxmi
ServerName 192.168.100.20
ErrorLog logs/192.168.100.20-error_log
CustomLog logs/192.168.100.20-access_log common
</VirtualHost>


内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://sulao.cn/post/38.html

我要评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。