Linux下Apache虛擬主機(jī)的三種配置荠耽。這樣可以實(shí)現(xiàn)一臺(tái)主機(jī)架構(gòu)多個(gè)獨(dú)立域名網(wǎng)站态坦。其中基于域名的最為常見。性價(jià)比也最高蜒滩。下面PHP程序員雷雪松詳細(xì)的講解下Linux下Apache虛擬主機(jī)配置的具體步驟寄雀。
1得滤、基于多ip地址的虛擬主機(jī)
Listen 80
DocumentRoot /home/httpd/html1
ServerName www.ok1.com
ErrorLog /usr/local/apache/logs/error1_log
CustomLog /usr/local/apache/logs/access1_log combined
DocumentRoot /home/httpd/html2
ServerName www.ok2.com
ErrorLog /usr/local/apache/logs/error2_log
CustomLog /usr/local/apache/logs/access2_log combined
2、基于多IP 和多端口的虛擬主機(jī)配置
Listen 12.34.56.78:80
Listen 12.34.56.78:8080
Listen 87.65.43.21:80
Listen 87.65.43.21:8080
DocumentRoot /www/example1-80
ServerName www.example1.com
DocumentRoot /www/example1-8080
ServerName www.example1.com
DocumentRoot /www/example2-80
ServerName www.example1.org
DocumentRoot /www/example2-8080
ServerName www.example2.org
3盒犹、單個(gè)IP 地址的服務(wù)器上基于域名的虛擬主機(jī)配置
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
DocumentRoot /www/example1
ServerName www.example1.com
ServerAlias example1.com. *.example1.com
# Other directives here
DocumentRoot /www/example2
ServerName www.example2.org
# Other directives here