以创建虚拟主机(a,b,c)为例子
1)2.1.2禁用默认的主机模式
123[root@localhost httpd]# vim /etc/httpd/conf/httpd.conf在主配置文件里面注释下面这行内容#DocumentRoot “/var/www/html”
2)在主配置文件添加监听端口
123找到Listen行,在原有行Listen 80行的基础上, 在添加一行Listen 8080 Listen 81
3)添加端口配置虚拟
12345678910111213[root@localhost httpd]#vim /etc/httpd/conf.d/virtualhost.conf<VirtualHost 192.168.87.131:80>DocumentRoot “/var/www/a”ServerName www.a.com</VirtualHost><VirtualHost 192.168.87.131:8080>DocumentRoot “/var/www/b”ServerName www.b.com</VirtualHost><VirtualHost 192.168.87.131:81DocumentRoot “/var/www/c”ServerName www.c.com</VirtualHost>
4)创建新目录
12345[root@localhost conf.d]# cd/var/www [root@localhost www]# mkdir a b c[root@localhost www]# echo welcome to www.a.com >> ./a/index.html[root@localhost www]# echo welcome to www.b.com >> ./b/index.html[root@localhost www]# echo welcome to www.c.com >> ./c/index.html
5)重启httpd
1[root@localhost ~]#systemctl restart httpd
注意:一定要重启httpd!!!
最新评论