我已经阅读了几篇文章并梳理了 stackExchange,但无法解决问题。我有两个域名,我想为每个域名创建虚拟主机。我创建了单独的文件夹,在其中托管每个域的index.html。我还创建了一个 conf 文件,在/etc/apache2/sites-available下,文件如下:
NameVirtualHost x.x.x.x:80
<VirtualHost x.x.x.x:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName example1.org
ServerAlias www.example1.org
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/org/public_html
#Options +FollowSymlinks
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
#<Directory /var/www/html/org/public_html>
# Options -Indexes +FollowSymLinks +MultiViews
# AllowOverride All
# Require all granted
#</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/example1aorg-error.log
CustomLog ${APACHE_LOG_DIR}/example1org-access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
<VirtualHost x.x.x.x:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName example2.com
ServerAlias www.example2.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/com/public_html
#Options +FollowSymlinks
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
#<Directory /var/www/html/com/public_html>
# Options -Indexes +FollowSymLinks +MultiViews
# AllowOverride All
#</Directory>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/example2com-error.log
CustomLog ${APACHE_LOG_DIR}/example2com-access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
xxxx是公共 IP
example1和example2不是我正在使用的域,而只是虚拟域。
当我尝试在我的服务器上加载域时,服务器总是向我显示example1的索引文件。
我不知道该怎么做,虚拟主机似乎无法与两个域一起使用。
编辑:我仍然无法弄清楚,这是我的域名:www.asanteniafrica.com www.asanteniafrica.org
我想相信这与域的 .org 和 .com 部分有关,我仍在研究。
如果您通过 apt 安装,您可能需要检查是否有默认配置。如果有,您应该通过将其从
sites-enabled
列表中删除来禁用它。如果不查看如何
example1.com
配置,很难判断问题出在哪里。但如果它的设置就像example2.com
,请确保它DocumentRoot
指向不同的目录。这很容易被忽视。快速编辑:VirtualHosts 肯定适用于多个域。我目前正在使用三个域和几个子域运行它,全部使用 VirtualHost。SSL虽然很棘手……但那是题外话。
+++
example1.com
提供配置后的附加编辑。没有评论,看起来你的配置是这样的:
除了域之外,这些之间的差异是
org
example1 和com
for example2。当您从浏览器访问 example2 时,它是否有日志?你也可以提供这些吗?好吧,在搜索和重建我的服务器之后,我终于找到了我的问题的答案。我实际上是将我的服务器 IP 转发到我的域,而不是配置 DNS。我从 GoDaddy 购买了我的域名,我的服务器使用 Linode。我按照以下说明配置我的 DNS。
https://www.linode.com/docs/platform/manager/dns-manager/
然后,使用以下指南登录 Godaddy.com 并将名称服务器添加到我的域中:
https://www.godaddy.com/help/set-nameservers-for-domains-hosted-and-registered-with-godaddy-12316
更新名称服务器后,URL 大约需要 48 小时才能通过浏览器指向正确的 webroot。