简体   繁体   English

对 apache2 服务器的请求总是重定向到 /var/www(/ 的索引)站点

[英]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.

相关问题 如何在Ubuntu的apache2服务器上获得对/ var / www / html的编辑权限 - how to get edit access to /var/www/html on apache2 server on Ubuntu 我无法将PHP中的文件复制到apache2 Web服务器中/ var / www之外的另一个目录中 - I can not copy a file in PHP to another directory out of /var/www in my apache2 web server 网站重定向到没有www的index.php - Site redirects to index.php without www 试图从不在/ var / www中的Apache2删除文件 - Trying to delete a file from Apache2 not in /var/www Apache2:访问除/ var / www之外的另一个目录中的文件 - Apache2: Access files within another directory than /var/www 访问位于 /var/www/xxxxx 和 /var/www/html/yyyyy 的 apache2 站点 - Access apache2 sites located in /var/www/xxxxx and /var/www/html/yyyyy 为什么将apache2 www目录移动到/ var / www / html? - Why has the apache2 www dir been moved to /var/www/html? 为什么 Apache 从 /usr/local/apache2/htdocs 而不是 /var/www/html 提供服务? - Why does Apache serve from /usr/local/apache2/htdocs and not /var/www/html? docker apache 容器将 /usr/local/apache2/htdocs 作为 DocumentRoot 而不是 /var/www/html - docker apache container serves /usr/local/apache2/htdocs as DocumentRoot instead of /var/www/html apache2中的PHP项目没有显示在http://localhost/中,php项目存储在/var/www/html - PHP Projects in apache2 are not displaying in http://localhost/, php projects are stored in /var/www/html
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM