2014-04-23 72 views
3

我想在一臺Apache服務器上託管多個不同域名的網站。在一臺linux服務器上有多個域名的多個網站

可以說我有以下網站:

www.site1.com 
www.site2.com 
www.site3.com 

我有一個IP地址(如:89.xxx),這是鏈接到我的/ var/www目錄,我可以從外部訪問,其結構如下:

/var/www/index.html // for www.site1.com 
/var/www/site2/index.html // for www.site2.com 
/var/www/site3/index.html // for www.site3.com 

在我的域名配置中,我將每個網站的A-Record指向同一個IP地址。 (我想避免轉發,例如http://89.x.x.x/site2,因爲iframe問題可能會導致網站的響應!)

我跟蹤了一些虛擬主機和htaccess配置的例子,但是他們都沒有工作!

因爲我在服務器配置方面不是很有經驗,所以我希望有任何建議可以解決這個問題!

謝謝堆!

回答

2

不能建立基於域名的虛擬主機在的.htaccess文件(來不及做約源目錄有什麼),所以你應該Apache主配置文件(S)在某處添加設置。

這下面的例子是從https://httpd.apache.org/docs/2.2/vhosts/name-based.html直接複製:

NameVirtualHost *:80 

<VirtualHost *:80> 
    ServerName www.domain.tld 
    ServerAlias domain.tld *.domain.tld 
    DocumentRoot /www/domain 
</VirtualHost> 

<VirtualHost *:80> 
    ServerName www.otherdomain.tld 
    DocumentRoot /www/otherdomain 
</VirtualHost> 
+0

我按照你的例子把它放在/ etc/apache2/site-available/default文件中,我重啓了apache並沒有任何效果! – zuubs

+0

可能有一些Ubuntu特有的挑戰,我不幸一無所知。也許這是有幫助的:http://askubuntu.com/questions/265300/how-do-i-setup-name-based-virtual-hosts-using-ubuntu-12-04 – krisku

0

追加到krisku的答案,我們應該加入的Apache2配置文件附加系的地方像httpd/conf目錄/ httpd.conf中:

<Directory "/www/domain"> 
# 
# Possible values for the Options directive are "None", "All", 
# or any combination of: 
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews 
# 
# Note that "MultiViews" must be named *explicitly* --- "Options All" 
# doesn't give it to you. 
# 
Options Indexes FollowSymLinks 

# 
# AllowOverride controls what directives may be placed in .htaccess files. 
# It can be "All", "None", or any combination of the keywords: 
# Options FileInfo AuthConfig Limit 
# 
AllowOverride all 

# 
# Controls who can get stuff from this server. 
# 
Require all granted 

<Directory "/www/otherdomain"> 
# 
# Possible values for the Options directive are "None", "All", 
# or any combination of: 
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews 
# 
# Note that "MultiViews" must be named *explicitly* --- "Options All" 
# doesn't give it to you. 
# 
Options Indexes FollowSymLinks 

# 
# AllowOverride controls what directives may be placed in .htaccess files. 
# It can be "All", "None", or any combination of the keywords: 
# Options FileInfo AuthConfig Limit 
# 
AllowOverride all 

# 
# Controls who can get stuff from this server. 
# 
Require all granted 

相關問題