httpd配置文件详解(三)

来源:互联网 发布:网络电子老虎机技巧 编辑:程序博客网 时间:2024/06/05 03:32

部署环境(关闭防火墙、selinux)

[root@miner_k ~]# cat /etc/redhat-release CentOS release 6.5 (Final)

第三部分:虚拟主机的配置

注:虚拟主机和中心主机的配置不能同时使用,如果使用虚拟主机需要将中心主机的DocumentRoot注释。

(1)基于IP地址的虚拟主机配置

Listen 80 <VirtualHost 172.20.30.40>     DocumentRoot /www/web1     ServerName www.miner_k.com </VirtualHost> <VirtualHost 172.20.30.50>     DocumentRoot /www/web2     ServerName www.miner_k.com </VirtualHost>在此处的ServerName是否相同都没有关系

(2) 基于IP和多端口的虚拟主机配置

Listen 172.20.30.40:80 Listen 172.20.30.40:8080 #这两处可以只写listen 80和listen 8080<VirtualHost 172.20.30.40:80>     DocumentRoot /www/web1     ServerName www.miner_k.com </VirtualHost><VirtualHost 172.20.30.40:8080>     DocumentRoot /www/web2    ServerName www.miner_k.com </VirtualHost>

(3)单个IP地址的服务器上基于域名的虚拟主机配置:

# Ensure that Apache listens on port 80 Listen 80# Listen for virtual host requests on all IP addresses NameVirtualHost *:80<VirtualHost *:80>     DocumentRoot /www/web1     ServerName www.miner_k1.com     ServerAlias example1.com. *.example1.com # Other directives here </VirtualHost><VirtualHost *:80>     DocumentRoot /www/web2     ServerName www.miner_k2.org     # Other directives here </VirtualHost>

在/www/web1和/www/web2中建立对应的index.html文件,即可测试。对于虚拟主机中的配置除了上述的参数还可以配置中心主机中的所有参数不如对不同目录的访问控制等。

0 0
原创粉丝点击