第一步,我们需要在/etc/httpd/conf/http.conf中监听 需要访问的端口号,比如你想访问8888这个端口下的内容,就监听8888端口
Listen 80
Listen 8888
按insert可以切换编辑状态,编辑好按Esc输入:wq可以保存退出 或者shift+zz 也可以退出保存
然后我们切换到/etc/httpd/ 目录下创建vhost-conf.d文件
cd vhost-conf.d
touch VirtualHost.conf
vim VirtualHost.conf
配置一下信息
<VirtualHost *:80>
ServerAdmin root@localhost
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:8888>
ServerAdmin root@localhost
DocumentRoot /var/www/heart
<Directory "/var/www/heart">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
然后回到主配置文件,vim /etc/httpd/conf/http.conf
IncludeOptional vhost-conf.d/*.conf
这样我们访问我们服务器网址 http:xxxx:80 http:xxxx:8888 就可以分别展示两个页面的内容了