二、基于端口的虚拟主机:
[root@localhost named]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf #编辑子配置文件 <VirtualHost 192.168.1.1:80> #配置监听端口号为80 ServerAdmin 916551516@qq.com DocumentRoot "/var/www/test1com" #正常访问的网站目录 ErrorLog "test1-error_log" CustomLog "test1-access_log" common <directory "/var/www"> require all granted </directory> </VirtualHost> <VirtualHost 192.168.1.1:8000> #配置监听端口号为8000 ServerAdmin 916551516@qq.com DocumentRoot "/var/www/test2com" #后台管理系统的网站目录 ErrorLog "test2-error_log" CustomLog "test2-access_log" common <directory "/var/www"> require all granted </directory> </VirtualHost> listen 8000 #监听8000,由于80端口默认监听,所以不用写listen 80,写上会报错 [root@localhost named]# vim /usr/local/httpd/conf/httpd.conf ...................... Include conf/extra/httpd-vhosts.conf #加载独立的配置文件 [root@localhost named]# systemctl restart httpd #重启httpd服务客户机访问:
注意:在访问时老实点输入:http://192.168.1.1:8000。不输入“http://”的话访问不到。
Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx