【问题标题】:Vistual host UBUNTU shows This site can’t be reached虚拟主机 UBUNTU 显示无法访问此站点
【发布时间】:2022-01-06 13:52:09
【问题描述】:

我在 Ubuntu 20.04.3 LTS 上配置了虚拟主机,但它不起作用。

首先创建的目录使用:

sudo mkdir -p /var/www/domain1.com/public_html

然后在其中创建 index.html 文件:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Welcome to domain1.com</title>
  </head>
  <body>
    <h1>Success! domain1.com home page!</h1>
  </body>
</html>

为了避免权限问题,我运行了这个命令:

sudo chown -R www-data: /var/www/domain1.com

然后在 /etc/apache2/sites-available 我创建了一个配置文件:

/etc/apache2/sites-available/domain1.com.conf

并把这段代码放进去

<VirtualHost *:80>
    ServerName domain1.com
    ServerAlias www.domain1.com
    ServerAdmin webmaster@domain1.com
    DocumentRoot /var/www/domain1.com/public_html

    <Directory /var/www/domain1.com/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/domain1.com-error.log
    CustomLog ${APACHE_LOG_DIR}/domain1.com-access.log combined
</VirtualHost>

然后运行这个命令:

sudo a2ensite domain1.com

然后使用命令重启apache:

sudo systemctl restart apache2

然后测试配置:

sudo apachectl configtest

并得到语法正常

的输出

但是当我在浏览器中访问 domain1.com 时,得到 "This site can’t be reached" 错误。

【问题讨论】:

    标签: ubuntu virtualhost ubuntu-12.04


    【解决方案1】:

    您已将 Apache 配置为特殊情况,它接收到 domain1.com 的任何请求

    你还没有:

    • 已注册 domain1.com
    • 使用 A 记录配置 DNS 服务器,将 domain1.com 指向 Apache 正在侦听的 IP 地址

    (或者使用hosts 文件之类的东西进行本地破解)。

    【讨论】:

      猜你喜欢
      • 2016-07-03
      • 1970-01-01
      • 2019-09-17
      • 2015-08-05
      • 1970-01-01
      • 1970-01-01
      • 2017-12-29
      • 1970-01-01
      • 2012-08-14
      相关资源
      最近更新 更多