【发布时间】:2026-02-02 02:50:01
【问题描述】:
提前谢谢你。
我只是按照 digitalocean 的教程进行操作:https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts。 我完成了所有指令,但是当我开始测试配置并从我的停车域添加一条 A 记录时,比如说 example.com,我的 digitalocean vps 地址是 192.168.10.2。 在这个方案中,我添加了这 3 个具有 3 个不同 DocumentRoot 的虚拟主机:
- /var/www/domainone.example.com/index.html
- /var/www/domaintwo.example.com/index.html
- /var/www/domainthree.example.com/index.html
然后在我的停车域中添加 3 条不同的 A 记录,如下所示:
- 名称:domainone.example.com 地址:192.168.10.2
- 名称:domaintwo.example.com 地址:192.168.10.2
- 名称:domainthree.example.com 地址:192.168.10.2
当我执行时,它发生如下:
- URL domainone.example.com 转到 /var/www/domainone.example.com/index.html
- URL domaintwo.example.com 转到 /var/www/domaintwo.example.com/index.html
- 但是此 URL domainthree.example.com 转到 /var/www/domaintwo.example.com/index.html
我确定我在 /etc/apache2/sites-available/(for each domain).config 处写了正确的 documentRoot 并重新启动 apache2 服务
再次感谢您
编辑
-
这是用于 /etc/apache2/sites-available/domaintwo.example.com.conf
<VirtualHost *: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 www.example.com ServerAdmin localhost@admin DocumentRoot /var/www/domaintwo.example.com/public ServerName domaintwo.example.com ServerAlias www.domaintwo.example.com # 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 ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/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 SSLEngine onSSLCertificateFile /etc/apache2/ssl/apache.crt SSLCertificateKeyFile /etc/apache2/ssl/apache.key
-
这是用于 /etc/apache2/sites-available/domainthree.example.com.conf
<VirtualHost *: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 www.example.com ServerAdmin localhost@admin DocumentRoot /var/www/domainthree.example.com/public ServerName domainthree.example.com ServerAlias www.domainthree.example.com # 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 ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/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 SSLEngine on SSLCertificateFile /etc/apache2/ssl/apache.crt SSLCertificateKeyFile /etc/apache2/ssl/apache.key </VirtualHost>
【问题讨论】:
-
我们可以提供您的
ApacheVirtualHosts 配置文件吗? -
@D4V1D 我只是添加了virtualhost的配置文件,请看一下:)
-
为什么没有domainone VirtualHost conf文件?
-
您能否在
sudo apache2ctl -S的输出中验证是否一切都按预期启用?
标签: ubuntu apache2 virtualhost a-records