[英]Request to apache2 server always redirects to /var/www (Index of /) site
I am currently trying to setup an virtual hosts following this tutorial on DigitalOcean .我目前正在尝试按照DigitalOcean 上的本教程设置虚拟主机。
The dummy-site I am trying to serve is under /var/www/example/html/index.html
.我尝试提供服务的虚拟站点位于
/var/www/example/html/index.html
下。 I have not registered an official domain but setup /etc/hosts/
to resolve example.com to the IP address of my server.我没有注册官方域,但设置
/etc/hosts/
将 example.com 解析为我服务器的 IP 地址。
I created another conf file called example.conf
under /etc/apache2/sites-available
and enabled it with sudo a2ensite example.conf
and disabled the 000-default.conf
.我在
/etc/apache2/sites-available
下创建了另一个名为example.conf
的 conf 文件,并使用sudo a2ensite example.conf
启用它并禁用000-default.conf
。
Now whenever I go to example.com
in my browser I get served:现在,每当我在浏览器中访问
example.com
时,我都会得到服务:
This is the same page I would get when directly going to the IP address of my server.这与我直接访问服务器 IP 地址时得到的页面相同。 Only when I got directly to
example.com/example/html
I get served the correct index.html
.只有当我直接访问
example.com/example/html
时,我才会得到正确的index.html
。
My current config looks like this:我当前的配置如下所示:
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And my /etc/hosts
file on my laptop like this:我笔记本电脑上的
/etc/hosts
文件是这样的:
#<ip-address> <hostname.domain.org> <hostname>
<server-ip> example.com
There are some other folders inside /var/www/
as the company I rented the server from had some maintenance sites preinstalled, but that shouldn't matter in this situation. /var/www/
中还有一些其他文件夹,因为我租用服务器的公司预装了一些维护站点,但在这种情况下这无关紧要。 (See edit, this did actually matter). (请参阅编辑,这确实很重要)。
It feels like I am missing something obvious here, but I can't find a solution for my problem.感觉我在这里遗漏了一些明显的东西,但我找不到解决问题的方法。
Edit:编辑:
The obvious thing I was missing, was that 2 additional sites where enabled by default as well.很明显,我遗漏了另外 2 个默认启用的站点。 One had the following contents:
一个有以下内容:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com
actually went to the right index.html
.禁用所有其他站点后,对
example.com
的请求实际上转到了正确的index.html
。
I figure, that the above enabled site actually matched the request coming from my browser and showed the www
root directory.我想,上面启用的站点实际上匹配了来自我的浏览器的请求并显示了
www
根目录。
The obvious thing I was missing, was that 2 additional sites where enabled by default as well.很明显,我遗漏了另外 2 个默认启用的站点。 One had the following contents:
一个有以下内容:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com
actually went to the right index.html
.禁用所有其他站点后,对
example.com
的请求实际上转到了正确的index.html
。
I figure, that the above enabled site actually matched the request coming from my browser and showed the www
root directory.我想,上面启用的站点实际上匹配了来自我的浏览器的请求并显示了
www
根目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.