免费资源网 – https://freexyz.cn/
apache:基于端口创建虚拟主机
以创建虚拟主机(a,b,c)为例子
1)2.1.2禁用默认的主机模式
[root@localhost httpd]# vim /etc/httpd/conf/httpd.conf 在主配置文件里面注释下面这行内容 #DocumentRoot “/var/www/html”2)在主配置文件添加监听端口
找到Listen行,在原有行Listen 80行的基础上, 在添加一行 Listen 8080 Listen 813)添加端口配置虚拟
[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:81 DocumentRoot “/var/www/c” ServerName www.c.com </VirtualHost>4)创建新目录
[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.html5)重启httpd
[root@localhost ~]#systemctl restart httpd注意:一定要重启httpd!!!
最后效果:
免费资源网 – https://freexyz.cn/
© 版权声明
THE END
暂无评论内容