搜尋此網誌

RHCE - Virtual Host


Virtual host 就是同個IP會有兩個host名稱
連http://Vserver.example.com  會顯示 this is serverX
連http://www3.example.com  會顯示 this is www3
這個LAB需要先把DNS Server先架設起來,將Vserver與www3都對應至192.168.122.103

[root@instructor~]#echo 'this is serverX.' > /var/www/html/index.html
[root@instructor~]#mkdir -p /www3/html
[root@instructor~]#echo 'this is www3.' > /wwwX/html/index.html
[root@instructor~]#vim /etc/httpd/conf/httpd.conf

在底下加入

NameVirtualHost *:80

<VirtualHost *:80>
     ServerAdmin webmaster@Vserver.example.com
     DocumentRoot /var/www/html/
     ServerName Vserver.example.com
     ServerAlias Vserver
</VirtualHost>

<VirtualHost *:80>
     ServerAdmin webmaster@www3.example.com
     DocumentRoot /www3/html/
     ServerName www3.example.com
     ServerAlias www3
</VirtualHost>

[root@instructor~]#ll -dZ /var/www/html
[root@instructor~]#semanage fcontext -a -t httpd_sys_content_t '/www3(/.*)?'
[root@instructor~]#restorecon -Rv /www3/
[root@instructor~]#service httpd restart

 

Copyright © Jackie.Chen | Powered by Blogger | Template by 54BLOGGER | Fixed by Free Blogger Templates