我想在一台apache服务器上托管多个具有不同域名的网站。
假设我有以下网站:
www.site1.com
www.site2.com
www.site3.com
我有一个ip地址(例如:89.x.x.x),它链接到我可以从外部访问的/ 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配置的一些示例进行了操作,但它们都没有工作!
由于我在服务器配置方面不是很有经验,所以我很感激您提出解决此问题的建议!
谢谢堆!
答案 0 :(得分: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>
答案 1 :(得分:0)
附加到krisku的答案,我们应该在httpd / conf / httpd.conf之类的地方在apache2配置文件中添加添加行:
<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