我已经阅读了几篇文章并梳理了 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 部分有关,我仍在研究。