使用虚拟主机时“无法访问此站点”

dnc*_*123 4 server apache2

我正在尝试设置 Apache2 服务器。安装和配置似乎进行得很顺利,但是当我尝试访问我的自定义 Web URL 时,出现“无法访问此站点”错误。我已尝试通过此答案设置配置文件 -尝试在浏览器中访问 Apache 2.4.7 Web 服务器时出现 Forbidden 403 错误

我的主机文件如下所示:

127.0.0.1   localhost
127.0.0.1       justtestingthis
127.0.1.1   Hacker

# The following lines are desirable for IPv6 capable hosts
...
Run Code Online (Sandbox Code Playgroud)

我的apache2/sites-available/http.justtestingthis.conf文件看起来像这样:

<VirtualHost 127.0.0.1:80>
    ServerAdmin webmaster@example.com
    ServerName justtestingthis.com
    ServerAlias www.justtestingthis.com

    DocumentRoot /home/donatas/Desktop/Projects/justtestingthis/dist/src
    DirectoryIndex index.php

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /home/donatas/Desktop/Projects/justtestingthis/dist/src>
        # Allow .htaccess 
        AllowOverride All
        Allow from All
    </Directory> 
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

我还在apache2/sites-enabled使用sudo a2ensite http.justtestingthis.conf.

当我通过输入http://localhost访问该网站时,我的网站被成功找到,但是当我尝试通过 justtestingthis.com 或 www.justtestingthis.com 访问它时,我得到“这个网站无法到达错误”...

我究竟做错了什么?

Ter*_*nce 9

您的浏览器无法打开justtestingthis.com页面的原因是没有别名指向它应该去的地方。您的/etc/hosts文件中只有127.0.0.1 justtestingthis,这只是名称。浏览器不知道名称 with 在哪里,.com因为它没有被指定。

要解决此问题,请将您的行更改/etc/hosts为:

127.0.0.1 www.justtestingthis.com 
Run Code Online (Sandbox Code Playgroud)

这现在应该是Apache 页面justtestingthis.comlocalhost或 的别名127.0.0.1。它也将在justtestingthis.com没有 www 的情况下打开。

希望这可以帮助!