centos6上虚拟主机的实现
實(shí)現(xiàn)虛擬主機(jī)有三種方式:基于IP的實(shí)現(xiàn)、基于端口的實(shí)現(xiàn)、基于FQDN的實(shí)現(xiàn)?
? ? ? ? ? ? ? ? ? ? ? ? ? 一、基于IP的實(shí)現(xiàn)
1.先創(chuàng)建三個(gè)站點(diǎn):
????mkdir /app/site1
????mkdir /app/site2
????mkdir /app/site3
2.在站點(diǎn)里面輸入內(nèi)容:
????echo /app/site1/index.html > site1/index.html
????echo /app/site2/index.html > site2/index.html
????echo /app/site3/index.html > site3/index.html
3.增加三個(gè)IP地址:
????ip add a 192.168.93.10/24 dev eth1
????ip add a 192.168.93.20/24 dev eth1
????ip add a 192.168.93.30/24 dev eth1
4.編輯配置文件:
????vim /etc/httpd/conf.d/test.conf
5.啟動(dòng)httpd服務(wù):service httpd start
6.測(cè)試:(統(tǒng)一說(shuō)明下,測(cè)試都是在centos7上做的,包括以下兩個(gè)實(shí)驗(yàn)。)
????curl http://192.168.93.10
????curl http://192.168.93.20
????curl http://192.168.93.30
注:建立虛擬主機(jī)時(shí),主站點(diǎn)可以關(guān)閉。每個(gè)站點(diǎn)占用一個(gè)IP地址,通常使用IP地址訪問(wèn)站點(diǎn)的用戶很少;或是配合DNS服務(wù)器上使用:
如:vim /etc/hosts
實(shí)現(xiàn)通過(guò)名字訪問(wèn)站點(diǎn):如圖所示
? ? ? ? ? ? ? ? ? ? ? ? ? ?二、基于端口的實(shí)現(xiàn)
1.編輯配置文件,添加三個(gè)端口:
????vim /etc/httpd/conf.d/test.conf
2.重啟網(wǎng)絡(luò)服務(wù):
????service network restart
3.重啟httpd服務(wù):
????service httpd restart
(注:這里可能會(huì)出現(xiàn)httpd服務(wù)起不來(lái),查看是不是因?yàn)閟elinux的設(shè)置,如果是,進(jìn)入配置文件修改設(shè)置,設(shè)置完重啟。或者通過(guò)命令臨時(shí)修改:setenforce 0
4.測(cè)試:
? ? ? ? ? ? ? ? ? ? ? ? ?三、基于FQDN的實(shí)現(xiàn)
1.在hosts文件中添加站點(diǎn):
????vim /etc/hosts
2.編輯配置文件:
????vim /etc/httpd/conf.d/test.conf?
3.啟動(dòng)服務(wù):service httpd restart(或使用命令!ser)
4.測(cè)試:
? ?centos7與centos6大致相同,只是必須對(duì)目錄授權(quán),且不需要NameVirutalHost指令。
注:一般虛擬機(jī)不要與main主機(jī)混用;因此,要使用虛擬主機(jī),一般先禁用main主機(jī)。禁用方法:注釋中心主機(jī)的DocumentRoot指令即可
? ?以上就是虛擬主機(jī)的實(shí)現(xiàn)了,歡迎多多指教。
轉(zhuǎn)載于:https://blog.51cto.com/600600880/1977037
總結(jié)
以上是生活随笔為你收集整理的centos6上虚拟主机的实现的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: ***远程连接MYSQL提示1130 -
- 下一篇: HDU 3336 KMP